Ahmadhc
Ahmadhc

Reputation: 173

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

Upvotes: 1

Views: 1818

Answers (2)

glenn jackman
glenn jackman

Reputation: 246807

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.

Upvotes: 1

fedorqui
fedorqui

Reputation: 289725

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

Upvotes: 5

Related Questions