Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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

How about:

sleep 3600; sudo <command>

anyway I would consider using cron in your case…

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top