bash script help?
Knute Johnson
ubuntu at knutejohnson.com
Mon Nov 14 15:47:51 UTC 2011
On 11/13/2011 10:15 PM, Nils Kassube wrote:
> Knute Johnson wrote:
>> I've got a bash script that I run in cron.daily to backup some data
>> to a jump drive. One of the commands in my script is to umount the
>> drive. If I write;
>>
>> if umount /dev/sdb1; then
>> #do something
>> fi
>>
>> it always does it even if the umount is successful.
>
> You mean: "if it fails"? Well, I can't confirm. Try this as root:
>
> if umount / 2>/dev/null; then echo 1;else echo 0;fi
>
> Here the output is "0", which I would expect. If I replace / with an
> unmountable partition, the output is "1".
>
>
> Nils
>
root at knutejohnson:/home/knute# if umount / 2>/dev/null; then echo 1;
else echo 0;fi
0
Why does this return success? The device is busy and can't be
unmounted. The unmountable disk /dev/sdc1 returns 0.
root at knutejohnson:/home/knute# if umount /dev/sdc1; then echo 1;else
echo 0;fi
umount: /dev/sdc1: not found
0
root at knutejohnson:/home/knute# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 75865184 8764396 63246964 13% /
none 505520 244 505276 1% /dev
none 512148 0 512148 0% /dev/shm
none 512148 992 511156 1% /var/run
none 512148 0 512148 0% /var/lock
root at knutejohnson:/home/knute# if mount /dev/sdb1 /media/usbdisk; then
echo 1;else echo 0;fi
1
root at knutejohnson:/home/knute# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 75865184 8764388 63246972 13% /
none 505520 244 505276 1% /dev
none 512148 0 512148 0% /dev/shm
none 512148 992 511156 1% /var/run
none 512148 0 512148 0% /var/lock
/dev/sdb1 15618044 7102312 8515732 46% /media/usbdisk
root at knutejohnson:/home/knute# if umount /dev/sdb1; then echo 1;else
echo 0;fi
1
root at knutejohnson:/home/knute# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 75865184 8764388 63246972 13% /
none 505520 244 505276 1% /dev
none 512148 0 512148 0% /dev/shm
none 512148 992 511156 1% /var/run
none 512148 0 512148 0% /var/lock
root at knutejohnson:/home/knute#
Both of the above appear to me to be wrong, they should both be showing
0 not 1. Then there is this;
root at knutejohnson:/home/knute# mount /dev/sdb1 /media/usbdisk;echo $?
0
root at knutejohnson:/home/knute# umount /dev/sdb1; echo $?
0
root at knutejohnson:/home/knute# umount /dev/sdb1; echo $?
umount: /dev/sdb1: not mounted
1
root at knutejohnson:/home/knute# mount /dev/sdc1 /media/usbdisk; echo $?
mount: special device /dev/sdc1 does not exist
32
There is something here I don't understand?
Thanks,
--
Knute Johnson
More information about the ubuntu-users
mailing list