Scripting file copy with notification upon completion
I am using Ubuntu to copy files contained within more than a hundred CD's to a single hard drive. When a CD's contents has finished copying to the hard drive, I receive no indication that it is done. I would like to create shell script that does the fol开发者_如何学编程lowing:
- Prompt me for a name to give a new folder
- Create the folder on the destination hard drive
- Copy the contents of CD currently in the cd drive to the new folder
- Notify me when the copy operation is complete
I've installed libnotify onto my computer, but I'm open to using other means of notification.
#!/bin/bash
while read -r -p "Enter a folder name: " name
do
[[ -z $name ]] && break # quit if user presses enter without input
mkdir -p "$name"
cp source "$name" # use your current copy method
# Notifications: choose one or all six or add your own
notify-send "Copy complete" "Folder: $name"
zenity --title="Copy complete" --text="Copying to folder $name is complete" --info&
dialog --title "Copy complete" --msgbox "\nCopying to folder\n$name\nis complete\n" 10 60
for i in {1..4}
do
printf '\a' # make some noise
sleep 1
done
echo "Copying to folder: $name is complete" | mail -S "Copy completion notification" keyslinger@example.com
printf 'Copy to folder %s is complete.\n' "$name"
done
Thanks, Dennis, it worked a charm! Just for reference, here's what I ended up using:
#!/bin/bash
while read -r -p "Enter a folder name: " name
do
[[ -z $name ]] && break # quit if user presses enter without input
cd /media/Iomega_HDD
mkdir -p "$name"
cdname=`volname`
cdname=${cdname%% *} #trim white space from variable holding cd name
cdname=${cdname#* }
cp -r /media/"$cdname"/. "$name"
# Notifications:
notify-send "Copy complete" "Folder: $name"
printf 'Copy to folder %s is complete.\n' "$name"
eject
done
精彩评论