Register
It is currently Sat Aug 02, 2014 2:35 am

My first script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Sat Jan 06, 2007 1:21 am   

Joined: Sat Jan 06, 2007 1:11 am
Posts: 2
Location: Lancashire, UK
Hi everyone, I'm getting into this scripting thing and here is my first script, Please let me know what you think, if I have done anything stupid or wrong.
Thanks


#! /bin/bash
#
#
# Mount or unmount specified drives to specified mountpoints
#

while getopts "VUh" Option
do
case $Option in
h) echo " "
echo "Mounting interactively mounts or umounts filesystems entered by user"
echo "Usage: amountscript [-VUh]"
echo "Options: -h print this help and exit"
echo " -V print version and exit"
echo " -U run script in unmount mode "
echo " "
exit;;
V) echo " "
echo "Mounting v0.3"
echo "Author J Greenwood"
echo "05/01/2007"
echo " "
exit;;
U) if
[ "$UID" -ne "0" ]
then
echo "Must be root to run this script"
exit
fi
echo "running Mounting in unmount mode"
YN=y
while [ "$YN" = "y" ]
do
echo -n "Enter device identifier (eg. /dev/hda1): "
read -e DEVICE
umount $DEVICE
echo -n "Unmount another? (y/n): "
read -e YN
if
[ "$YN" = "y" ]
then
echo ""
else
exit
fi
done
exit;;
esac
done


# Checks to see if you are root, if not you can't run the script
# and you will be told this in red

if
[ "$UID" -ne "0" ]
then
echo "This script must be run as root"
exit
fi

YN=y

# Keep looping until you say no to mount another
# Asks for information about the drive you want to mount
# And mounts it according to your answers

while [ "$YN" = "y" ]
do
echo -n "Enter device identifier (eg. /dev/hda1): "
read -e DEVICE
echo -n "Enter mountpoint (eg. /mnt/hda1): "
read -e MOUNTPOINT
echo -n "Would you like to mount $DEVICE read-only? (y/n): "
read -e RONLY
echo -n "Would you like to specify a filesystem type? (y/n): "
read -e FILETYPEYN


if
[ "$FILETYPEYN" = "y" ]
then
if
[ "$RONLY" = "y" ]
then
echo -n "Which filesystem does your device use? (eg. ext3): "
read -e FILETYPE
mount -t $FILETYPE $DEVICE $MOUNTPOINT -o ro
elif
[ "$FILETYPEYN" = "y" ]
then
echo -n "which filesystem does your device use? (eg. ext3): "
read -e FILETYPE
mount -t $FILETYPE $DEVICE $MOUNTPOINT
fi
fi

if
[ "$FILETYPEYN" = "n" ]
then
if
[ "$RONLY" = "y" ]
then
mount $DEVICE $MOUNTPOINT -o ro
elif
[ "$FILETYPEYN" = "n" ]
then
mount $DEVICE $MOUNTPOINT
fi
fi

# Asks if you want to mount another device

echo -n "Mount another? (y/n): "
read -e YN

if
[ "$YN" = "y" ]
then echo ""
else
exit
fi
done

exit


Top
 Profile  
 PostPosted: Tue Jan 09, 2007 9:30 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 664
Location: Des Moines, Iowa
Welcome to bashscripts johngreenwood ;)


Top
 Profile WWW  
 PostPosted: Wed Jan 17, 2007 4:06 pm   

Joined: Fri Oct 14, 2005 9:30 am
Posts: 61
Yup welcome :).
Woah thats your first script :o ?
Sure beats the hell out of mine :lol:


Top
 Profile WWW  
 PostPosted: Tue Jan 23, 2007 4:26 pm   

Joined: Mon Dec 11, 2006 3:26 pm
Posts: 18
my first was hello world

put it on a server and watched the boss cringe as i ran it (he didn't know what it was until after)


Top
 Profile  
 PostPosted: Sun Feb 18, 2007 8:43 pm   

Joined: Sat Jan 06, 2007 1:11 am
Posts: 2
Location: Lancashire, UK
It, took me about 2 days to write it, with the help of the Advanced Bash Scripting Guide: http://tldp.org/LDP/abs/html/


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP