Shell文件自动替换脚本
2013-06-20 23:56
489 查看
文件替换脚本
使用方法:
./file-update.sh 文件名 大致路径(确定再那个路径下搜索)
脚本演示:
执行过后会再/mnt/backup/创建一个时间的文件夹
并将所要替换文件移到上步新建的文件夹里
将新文件替换过去
最后删除新文件
本文出自 “浮躁的产品汪” 博客,请务必保留此出处http://haolulu.blog.51cto.com/3164472/1226299
使用方法:
./file-update.sh 文件名 大致路径(确定再那个路径下搜索)
#! /bin/bash date1=`date +%Y%m%d%s` date2=`date +%Y%m%d` if [ -e /mnt/backup/$date2 ] ; then : else mkdir -p /mnt/backup/$date2 fi # backup-file backup-file () { echo "Do you want to backup this file? please select `echo "[y/n]"` " read FILE case $FILE in y) file1=$i file2=$1 s=${file1##/*/} r=${file2:=$s} cp $i /mnt/backup/$date2 && echo "backup file ok" || echo "backup file fail" ;; n)echo "NOT BACKUP file" ;; *) backup-file ;; esac } # update-file update-file () { echo "do you want to UPDATE this file ? please select `echo [y/n]`" read FILE case $FILE in y) file1=$i file2=$1 s=${file1##/*/} r=${file2:=$s} cp $r $i && echo "update file ok" && rm -rf $r || echo "update file fail" ;; n) echo "NOT UPDATE file" ;; *) update-file ;; esac } # find backup update update-file Path=${2:?请输入替换文件大致路径} select i in `find $Path -name $1`; do backup-file update-file break done
脚本演示:
执行过后会再/mnt/backup/创建一个时间的文件夹
并将所要替换文件移到上步新建的文件夹里
将新文件替换过去
最后删除新文件
本文出自 “浮躁的产品汪” 博客,请务必保留此出处http://haolulu.blog.51cto.com/3164472/1226299
相关文章推荐
- 【shell脚本】ftp自动上传mysql备份文件
- linux中使用shell脚本自动登录ftp服务器下载上传文件。
- linux 批量scp自动上传文件的shell脚本
- CentOS Linux自动备份文件到远程FTP服务器并删除指定日期前的备份Shell脚本
- linux中在多个文件中查找替换文本的shell脚本
- 用shell脚本在linux下删除和替换文件
- shell 脚本自动下载文件
- 自动删除指定时间内的日志和文件shell脚本
- python写一段脚本代码自动完成输入(目录下的所有)文件的数据替换(修改数据和替换数据都是输入的)【转】
- 通过FTP自动上传文件到目标机的shell脚本
- shell中通配符无法使用和/使用dev/null文件自动清除日志脚本
- web服务文件更新自动同步、数据库主从复制、shell脚本实现网站代码备份和mysql备份
- shell脚本实现自动生成文件并更改其权限
- shell脚本实现自动压缩一天前的日志文件并传到ftp服务器上
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中(转)
- shell脚本自动查找指定路径下包含某关键字的所有文件
- shell脚本,自动登陆ftp,下载文件
- shell 脚本替换文件中某个字符串
- Shell脚本自动删除指定大小以上的备份文件
- shell脚本自动下载 symantec病毒库升级文件