Search code examples
linuxcron

crontab add a wait time between move, copy, unzip, move


How to add a wait time between crontab jobs commands?

There may be other errors in this code. But the main goal is at 10pm to execute one line, wait for the previous to complete, then move to the next, etc...

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/

Solution

  • Answer thanks to Nate Eldredge, just put it all together in-case useful to anyone. Also, thanks to Tink.

    crontab -e #then enter code in the editor #Note $USER may need to be changed to your name.

    * 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/