I have a directory called directory1 to which we store some files daily.
I first try to remove the previous backup stored in directory2. Then I try to move the files in directory1 to directory2. I run the following bash script with cron but seems to fail.
What is wrong with my code?
#!/bin/sh
/bin/rm -rf /directory2/*
/bin/mv /directory1/* /directory2/
And my /etc/crontab has the following line:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.