Jenny M Jenny M - 9 months ago 43
Bash Question

Build scripts with command delay

Im using in the command line for 3 commands and I since that I'm doing that over and over again I want to build some script, the problem is like following :

This is what Im doing

1 . cd

- > tar czf ../fts/runnerer.tar App/

This take about 2 sec

2 . cd
- > cf update-run myBP -p /home/d56789/fts/ -i 4

This take about 8 sec

  1. cd
    -> cf push

This take about 30 sec

My question is how can I build script that can do this commands one after other with the needed delay between them ?

Answer Source

Commands are normally executed in sequence. For example the tar command in your question, while it's running, you cannot start running something else. You have to wait for it to complete.

As such, you can simply list the commands you want to do in your script, and they will be executed one after another. It doesn't matter if one commands takes 2 seconds or 22, the next command will not run until the previous is completed.

set -e

cd users/home/d56789/tmp
tar czf ../fts/runnerer.tar App/
cd ../fts
cf update-run myBP -p /home/d56789/fts/ -i 4
cd ../myapp
cf push

I added the set -e at the top for your safety. What it does is, if any of the commands fail, the script will exit without executing the rest.

If you really actually need a delay for some reason (I don't see such reason in your question), then you can use the sleep command. It takes the number of seconds as parameter, so to sleep 10 seconds run sleep 10, to sleep 5 minutes run sleep 300.