首页 > 其他 > 详细

交互脚本示例(2)-数据备份

时间:2015-08-14 19:42:29      阅读:231      评论:0      收藏:0      [点我收藏+]
#!/bin/bash
read -p "input the source file or directory you want to backup(absolute path): " sour

if [ ! -e $sour ]; then
   echo "the source file or directory not exits.the script is end."
     exit 1
fi


read -p "input the targe filename or directoryname(absolut path): " tar
if [ -e $tar ]; then
   echo "the target is exits"
   read -p "do you need to rename?(yes|no)" yn
   case $yn in
   yes|y)
         read -p "input the new name(absolut path): " newname
         mv $tar $newname
         cp -r $sour $tar
         echo "backup success" ;;
   no|n)
         if [ -d $tar ]; then
            cp -r $sour $tar
            echo "backup success"
         else
            echo "can not backup"
            exit 2
         fi
         ;;
   esac
else
   tdir=`dirname $tar`
   mkdir -r $tdir &> /dev/null
   cp -r $sour $tar
   echo "backup success"
fi


交互脚本示例(2)-数据备份

原文:http://chomper.blog.51cto.com/7866214/1684506

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!