[英]shell scripting: moving files to another directory
I have a directory called directory1 to which we store some files daily. 我有一个名为directory1的目录,我们每天都会存储一些文件。
I first try to remove the previous backup stored in directory2. 我首先尝试删除存储在directory2中的先前备份。 Then I try to move the files in directory1 to directory2.
然后我尝试将directory1中的文件移动到directory2。 I run the following bash script with cron but seems to fail.
我用cron运行以下bash脚本但似乎失败了。
What is wrong with my code? 我的代码出了什么问题?
#!/bin/sh
/bin/rm -rf /directory2/*
/bin/mv /directory1/* /directory2/
And my /etc/crontab has the following line: 我的/ etc / crontab有以下行:
0 6 * * 6 root /root/scripts/files.move.sh
I don't see why your commands would fail, but the script can be made more defensive: 我不明白为什么你的命令会失败,但脚本可以更加防御:
set -e; # bash specific, fail on error
/bin/mv /directory2 /directory3
/bin/mv /directory1 /directory2
/bin/rm -rf directory3
/bin/mkdir -p /directory1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.