简体   繁体   中英

linux script to run multiple commands at specific time

I need some help in writing a Linux script that do the following:

command 1
command 2
wait 10 minutes
command 3
command 4

and this script should run automatically at specific time for example 4 am...

Thank in advance

You can create a script.sh like:

#!/bin/bash

command 1
command 2
sleep 600 # 600 seconds = 10 min
command 3
command 4

And then create a cronjob:

0 4 * * * /bin/bash /path/to/script.sh

You can see more info of cron in https://stackoverflow.com/tags/cron/info

if you want the job to run once at a future time, instead of cron use at

at 4am tomorrow <<END
command 1
command 2
sleep 600
command 3
command 4
END

One of the advantages of at is that it will execute the commands using your current environment. The limited environment provided by cron is a cause of confusion for many people.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM