• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

unix shell scripting

paul60

Junior Member
Hello everyone, I need your help.

I want to write a script that Performs a recursive directory listing on the user's home directory and save the information to a file. Compress the file, have the script prompt the user to insert a USB flash drive, then press ENTER. Finally, save the file to the flash drive after making certain the flash drive has properly mounted by parsing the output of df. Note that the flash drive must be unmounted before it is removed.

this is what i have so far... but am stuck

#!/bin/bash
ls -R > groupfour.txt #performing recursive home directory listing and copying to a text file groupfour
gzip groupfour.txt # compressing the file
echo "insert a USB flash drive," #prompting the user to insert a flash drive
echo "and then press ENTER."
read ans
cp groupfour.txt.gz /cygdrive/h

Thank you in advance.
 
Stuck on what?

Inserting a drive is ... my system does not automount them. My desktop does show an icon, which has explicit "mount" option. Some desktops do automount on hotplug. Automount could be configured to mount on access attempt though, which is independent from desktop. One could use the "mount" command on script too.

Mount-point of a hotplugged device does vary too; there are multiple conventions. I would not use "df".

Unmount/eject ... depends on how it was mounted.
 
thanx, am using cygwin by the way am stuck at the point when a user has inserted a flash drive and pressed ENTER. I want the script be able to check whether the flash drive has been inserted/mounted correctly.
like...
if(drive mounted correctly)
{
then
(save zipped file on drive and unmount drive after)

}
else
{
(prompt user to insert flash drive)
}
 
Not sure why I'm looking at an such an old post, but something quick since I started replying before checking the date:

Code:
flashdrive=/cygdrive/h
echo "Please mount your flash drive..."
while [ ! -d "${flashdrive}" ]
do
        sleep 1
done
echo "Found flash drive, moving on..."

If you dont want to test that the mount point exists, just test the status of the command you want to use to verify the thumb drive is mounted. I'm not familiar with cygwin, but you can probably grep /etc/fstab for the name if you know it. Then obviously use umount to unmount it. If you are interested in actually looking for a carriage return only:

Code:
echo "Please mount your flash drive.  Press ENTER to continue..."
read ans
while [ ! "${ans}" = $'' ]
do
     echo "WTF...I said ENTER biotch!  Press ENTER to continue!!!"
done

But you should probably just accept any input as being ready to continue.
 
Back
Top