0

I'd like to run a script at 6pm on a remote server but don't want to wait around to trigger it. I don't want to use cron since it's a one time deal.

Can I do something like "nohup myscript &" with a "sleep" or "after" command?

Thanks!

user41172
  • 145
  • 2
  • 5

3 Answers3

6

Are you sure you aren't looking for something like at.

Zoredache
  • 128,755
  • 40
  • 271
  • 413
  • I think you're right! would you mind posting the right syntax? is it "nohup script.sh | at now +4 hours &" ? (just a guess, clearly! thanks – user41172 Apr 21 '10 at 22:43
  • at queues and executes whatever you give it on stdin, so syntax is e.g. 'echo script.sh | at now +4 hours'. you don't need nohup with at. see the man page for at for more details. – cas Apr 22 '10 at 00:36
6

You can use the at (man at) command to do this, and then you don't need the nohup.

If you really wanted to, you could:

nohup bash -c 'sleep 5; command' &

But you might be better off running the command in screen and then use sleep before it so you can easily check the output.

Kyle Brandt
  • 82,107
  • 71
  • 302
  • 444
  • Thanks for this! I don't have permission to run `at` evidently, but am able to run sleep. So I came up with this monstrosity: `nohup bash -c 'sleep $((\`date -d "Wed Aug 9 09:15:00 CDT 2017" +%s\` - \`date +%s\`)); nice mpstat -P ALL 2 12300 > mpstat.log' &` – aakoch Aug 08 '17 at 21:46
1

You could create another shell script that does the sleep then runs your command.

cat > x.sh
sleep 5
yourcommand.sh
^D

nohup x.sh &