Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running delayed command with sudo

Want run a bash script as root but delayed. How can achieve this?

sudo "sleep 3600; command" , or
sudo (sleep 3600; command)

does not works.

like image 405
kobame Avatar asked Jun 16 '11 10:06

kobame


2 Answers

You can use at:

sudo at next hour

And then you have to enter the command and close the file with Ctrl+D. Alternatively you can specify commands to be run in a file:

sudo at -f commands next hour
like image 90
Rajish Avatar answered Sep 19 '22 06:09

Rajish


If you really must avoid using cron: sudo sh -c "(sleep 3600; command)&"

like image 25
chrisdowney Avatar answered Sep 18 '22 06:09

chrisdowney