You are not logged in.

#1 2008-01-24 22:08:12

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

[DONE] mount iso's script. little help needed

Hi! i made this little and useful (for me) script to mount my isos in my mount points, but im having problems validating the entered values, the while instruction is the one i dont know how to enter the "or" option...

TNKS!! hope you can find it useful!

#!/bin/bash
echo Select the mount point:
echo 1. /mnt/iso
echo 2. /mnt/iso2
echo 3. /mnt/iso3
echo 4. /mnt/iso4
read point
#while ( $point != "1" || $point != "2" || $point != "3" || $point != "4" ); do
#    echo invalid option
#       echo Select a valid mount point
#    read point
#done
case $point in
1) sudo mount -o loop -t iso9660 "$1" /mnt/iso1 && echo "$1" mounted to /mnt/iso1;;
2) sudo mount -o loop -t iso9660 "$1" /mnt/iso2 && echo "$1" mounted to /mnt/iso2;;
3) sudo mount -o loop -t iso9660 "$1" /mnt/iso3 && echo "$1" mounted to /mnt/iso3;;
4) sudo mount -o loop -t iso9660 "$1" /mnt/iso4 && echo "$1" mounted to /mnt/iso4;;
*)
esac
echo Select dir to umount:
echo 1. /mnt/iso1
echo 2. /mnt/iso2
echo 3. /mnt/iso3
echo 4. /mnt/iso4
read upoint
#while ( $upoint != "1" || $upoint != "2" || $upoint != "3" || $upoint != "4" ); do
#    echo invalid option
#       echo Select a valid mount point
#    read upoint
#done
case $upoint in
1) sudo umount /mnt/iso1 && echo /mnt/iso1 umounted;;
2) sudo umount /mnt/iso2 && echo /mnt/iso2 umounted;;
3) sudo umount /mnt/iso3 && echo /mnt/iso3 umounted;;
4) sudo umount /mnt/iso4 && echo /mnt/iso4 umounted;;
*)
esac
exit 0

Last edited by leo2501 (2008-01-26 16:15:52)


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#2 2008-01-24 22:44:48

ProzacR
Member
Registered: 2007-04-29
Posts: 272

Re: [DONE] mount iso's script. little help needed

I think remove sodo from script and run script with:
sudo script.sh

And if you want "or" try to use "if".

Offline

#3 2008-01-24 22:45:53

dmartins
Member
Registered: 2006-09-23
Posts: 360

Re: [DONE] mount iso's script. little help needed

Try this:

while [[ $point != "1" || $point != "2" || $point != "3" || $point != "4" ]]; do
    echo invalid option
       echo Select a valid mount point
    read point
done

Kind of a guess! Have you come across the advanced bash scripting guide? http://tldp.org/LDP/abs/html/
From chapter 7.1:

Using the [[ ... ]] test construct, rather than [ ... ] can prevent many logic errors in scripts. For example, the &&, ||, <, and >  operators work within a [[ ]] test, despite giving an error within a [ ] construct.

Offline

#4 2008-01-25 23:15:23

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: [DONE] mount iso's script. little help needed

nop, it doesnt work, even if i enter 1,2,3,4 always says "invalid option" sad


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#5 2008-01-26 09:48:55

gradgrind
Member
From: Germany
Registered: 2005-10-06
Posts: 921

Re: [DONE] mount iso's script. little help needed

Maybe you meant something like this (with AND!):

while [ "$point" != "1" ] && [ "$point" != "2" ] && [ "$point" != "3" ] && [ "$point" != "4" ]; do

Offline

#6 2008-01-26 16:15:33

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: [DONE] mount iso's script. little help needed

Perfect! here is the finished script

#!/bin/bash
echo Select the mount point:
echo 1. /mnt/iso1
echo 2. /mnt/iso2
echo 3. /mnt/iso3
echo 4. /mnt/iso4
echo 5. /mnt/cdrom
read point
while [ "$point" != "1" ] && [ "$point" != "2" ] && [ "$point" != "3" ] && [ "$point" != "4" ] && [ "$point" != "5" ]; do
    echo invalid option
    echo Select a valid mount point
    read point
done
case $point in
1) sudo mount -o loop -t iso9660 "$1" /mnt/iso1 && echo $1 mounted to /mnt/iso1 && echo --- Press a key to umount --- && read && sudo umount /mnt/iso1 && echo /mnt/iso1 umounted;;
2) sudo mount -o loop -t iso9660 "$1" /mnt/iso2 && echo $1 mounted to /mnt/iso2 && echo --- Press a key to umount --- && read && sudo umount /mnt/iso2 && echo /mnt/iso2 umounted;;
3) sudo mount -o loop -t iso9660 "$1" /mnt/iso3 && echo $1 mounted to /mnt/iso3 && echo --- Press a key to umount --- && read && sudo umount /mnt/iso3 && echo /mnt/iso3 umounted;;
4) sudo mount -o loop -t iso9660 "$1" /mnt/iso4 && echo $1 mounted to /mnt/iso4 && echo --- Press a key to umount --- && read && sudo umount /mnt/iso4 && echo /mnt/iso4 umounted;;
5) sudo mount -o loop -t iso9660 "$1" /mnt/cdrom && echo $1 mounted to /mnt/cdrom && echo --- Press a key to umount --- && read && sudo umount /mnt/cdrom && echo /mnt/cdrom umounted;;
*)
esac

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#7 2008-01-26 19:23:20

underpenguin
Member
Registered: 2007-02-01
Posts: 116

Re: [DONE] mount iso's script. little help needed

Hey, just my 2 cents,
http://devmanual.gentoo.org/tools-refer … ts-in-bash
Apparently double brackets are better than single. I've just started trying to get into bash scripting, and I ran into that, pretty interesting.

Very nice script btw, definitely adding it to my growing collection smile

Offline

Board footer

Powered by FluxBB