Running a delayed command using sudo

Do you want to run the bash script as root, but delay it. How can this be achieved?

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

does not work.

+6
source share
3 answers

You can use at :

 sudo at next hour 

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

 sudo at -f commands next hour 
+18
source

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

+3
source

What about:

 sleep 3600; sudo <command> 

In any case, I would consider using cron in your case ...

-2
source

Source: https://habr.com/ru/post/890663/


All Articles