How do I make a sudo command start at start-up with a 1 minute delay?

Solution 1:

A) If it's at system start-up, add this to the end of your /etc/rc.local (1): (before the exit 0, obviously):

( sleep 60 && service smbd restart )& 

Note:

  1. the outer () are needed so that the complex command detach itself and go to the background, allowing the boot process to finish;
  2. sudo is not needed there, /etc/rc.local is executed by root;
  3. Are you really sure this is a solution? It is a race condition asking to happen...

B) if it's at user login, you need two steps:

  1. configure your sudo so that it will not ask for a password for service smbd restart command (see How do I run specific sudo commands without a password?);

  2. prepare a script with the following contents and add it to your autorun/startup program (varies with the desktop environment you are using).

Script:

#!/bin/bash
( sleep 60 && service smbd restart )& 

Footnotes

(1) check if /etc/rc.local is executable. Otherwise, make it so with sudo chmod +x /etc/rc.local

Solution 2:

Try man sleep:

sleep 60 && sudo service smbd restart

Put this in the autorun programs or scripts executed at login time.