Saturday, February 07, 2015

Mount non Linux drives automatically when they are not in /etc/fstab

So, I usually face this problem when I'm not using GUI based File Managers. They allow you to auto mount drives when you click on them but when you are using CLI based file managers or no file managers at all, the only way is to mount them through writing commands. I'm a lazy fad and I want this done automatically. So here's a script for that. [ https://gist.github.com/Tafhim/5d0839caca813ae82c97 ].
#!/usr/bin/zsh
if [[ "$1" == "" ]] then
  echo "Please specify a device name";
  exit;
fi;
deviceFile=$1
 
## Auto mount only ntfs, fat32, vfat
for i in $(ls $deviceFile* | grep '[0-9]$'); do
  blkid -s UUID -o value $i | read z;
  blkid -s TYPE -o value $i | read f;
  echo "$z is $f";
  if [[ "$z" !=  "" && ("$f" == "ntfs" || "$f" == "vfat" || "$f" == "fat32" ) ]] then
    /usr/bin/udisksctl mount -t $f -b $i # https://help.ubuntu.com/community/AutomaticallyMountPartitions
  fi;
done

No comments:

Post a Comment

Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...