Skip to content

Instantly share code, notes, and snippets.

@andykais
Last active August 29, 2015 14:23
Show Gist options
  • Save andykais/d948751a6ca978dd6824 to your computer and use it in GitHub Desktop.
Save andykais/d948751a6ca978dd6824 to your computer and use it in GitHub Desktop.
script for mounting the usb/hdd drives on my pi upon startup
#!/bin/bash
sudo blkid | grep sda | while read -r line
do
USB=$(echo $line | perl -pe 's/\:(.*)//')
TYPE=$(echo $line | perl -pe 's/(.*)TYPE=// and s/"//g')
DIR=$(echo $line | perl -pe 's/(.*)\/// and s/\:(.*)//')
if [ -z "$(mount | grep $USB)" ]
then
mountinfo="mounting $USB of type $TYPE on /media/$DIR"
sudo mkdir -p /media/$DIR
sudo mount -t $TYPE $USB /media/$DIR
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment