码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-14 19:42:52      阅读:129      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!