脚本文件副本,包含完成后的通知

时间:2011-01-30 21:20:05

标签: shell ubuntu copy backup

我正在使用Ubuntu将包含在一百多张CD中的文件复制到一个硬盘驱动器中。当CD的内容已完成复制到硬盘驱动器时,我没有收到任何已完成的指示。我想创建执行以下操作的shell脚本:

  1. 提示我输入新文件夹的名称
  2. 在目标硬盘上创建文件夹
  3. 将当前CD驱动器中的CD内容复制到新文件夹
  4. 复制操作完成时通知我
  5. 我已将libnotify安装到我的计算机上,但我愿意使用其他通知方式。

2 个答案:

答案 0 :(得分:3)

#!/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

答案 1 :(得分:1)

谢谢,丹尼斯,它有魅力!仅供参考,以下是我最终使用的内容:

#!/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