Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
mount_safely (){
PARTITION=$1; MOUNTPOINT=$2
if [ `whoami` == root ];then
# create mount point dir if doesn't exists
[ -d $MOUNTPOINT ] || mkdir -p $MOUNTPOINT
# mount the partition to mountpoint
mount $PARTITION $MOUNTPOINT
# If mounting successful
if [ $? -eq 0 ]; then echo "Mounted: $PARTITION ==> $MOUNTPOINT";fi
else
echo "Mounting Error: $PARTITION ==> $MOUNTPOINT, Root permission required."
fi
}
# Log the errors to a log file
LOGFILE="/var/log/mount_error.log"
if [[ `whoami` == root ]];then exec 2> $LOGFILE; fi
# ----------- Modify as required ----------------
PARTITION="/dev/mmcblk1"
MOUNTPOINT="/media/sdcard"
mount_safely $PARTITION $MOUNTPOINT
# -----------------------------------------------
# Read out the errors from log file
if [[ `whoami` == root ]];then echo "Logged at `date`" >> $LOGFILE; echo `cat $LOGFILE`; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment