首页 > 解决方案 > crontab 在移动、复制、解压缩、移动之间添加等待时间

问题描述

如何在 crontab 作业命令之间添加等待时间?

此代码中可能还有其他错误。但主要目标是在晚上 10 点执行一行,等待上一个完成,然后移动到下一个,等等......

crontab -e

#* 22 * * * ##At 10pm, do the following in order waiting for each to complete before moving on.


mv /home/$USER/isengard /home/$USER/middleearth/mirkwood
wait
cp -r -p /home/$USER/middleearth/mirkwood /home/$USER/middleearth/shire/
wait
mv /home/$USER/middleearth/mirkwood /home/$USER/middleearth/rohan/
wait
gunzip -r /home/$USER/middleearth/rohan/
wait
mv /home/$USER/middleearth/rohan /home/$USER/middleearth/gondor/

标签: linuxcron

解决方案


感谢 Nate Eldredge 的回答,只需将它们放在一起,以防万一对任何人有用。另外,感谢 Tink。

crontab -e #then 在编辑器中输入代码 #Note $USER 可能需要改成你的名字。

* 22 * * * mkdir -p /home/$USER/me/arnor/hobbits/ ; cp -r -p /home/$USER/me/arnor/hobbits/ /home/$USER/me/shire/ ; mv /home/$USER/me/arnor/hobbits/ /home/$USER/me/buckland/ ; gunzip -r /home/$USER/me/buckland/hobbits ; mv /home/$USER/me/buckland/hobbits /home/$USER/me/gondor/

推荐阅读