About Me

My photo
I know the last digit of PI

Thursday, June 07, 2018

Generate random password with bash script

This is a utility script that generate random password
#!/bin/bash

size=10

if [[ "$1" == "-h" || "$1" == "--help" ]]; then
  echo "randpw [size]"
  exit 0
elif [[ "$1" != "" ]]; then
  size="$1"
fi

cat /dev/urandom | env LC_CTYPE=C tr -dc '!@#.1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM' | head -c$size
echo ""

Monday, May 07, 2018

Unmount all cifs shares before sleep/hibernate/suspend

I noticed when I close the lid of my laptop and there are mounted cifs shares, it takes 2 minutes before I am able to login after resume. I track down the problem to samba trying to reconnect mounted shares. The easiest way to fix that is to unmount everything before Fedora is going to sleep. Just create a script in /usr/lib/systemd/system-sleep/mounts with following content:
#!/bin/bash

case "${1}" in
  pre)
  # your command to umount here
    for m in `mount | grep /mnt | grep // | grep cifs | awk '{print $3}'`; do 
      echo "Unmounting $m"
      umount -f $m
    done 
  ;;
  post)
  # (possibly) your command to mount here
  ;;
esac