Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I use this

sleep 900; <command>

on my shell. Just wanted to know is there is some alternate/better way that you use?

share|improve this question
4  
you can do sleep 15m && command, that way if you want to cancel it you can ctrl-c it (your version would run the command if you ctrl-c it). –  OneOfOne Apr 25 '11 at 0:54
    
@OneOfOne I don't know if it's shell or something else dependent, but I've never seen Ctrl+C fallthrough like that; it cancels the entire line –  Michael Mrozek Apr 25 '11 at 8:28
    
@Michael I coulda swore it used to do that with older bash, I just tried and it didn't, so ignore my comment –  OneOfOne Apr 25 '11 at 18:37
1  
@OneOfOne: It did up to bash 3.x; that's fixed in bash 4. –  Gilles Apr 25 '11 at 21:58
    
Thanks @Gilles, I thought I was being crazy :D –  OneOfOne Apr 26 '11 at 4:21
add comment

2 Answers 2

up vote 23 down vote accepted

You are searching for at (at@wikipedia)?

usr@srv % at now + 15 min
at> YOUR COMMAND HERE

You can define multiple commands that should be executed in 15 min, seperate them with a return.
Confirm all commands with control+d.

share|improve this answer
add comment

I use a short script I keep in my path, called after, containing

at now + "$@"

This way it's very easy to, for example, type:

after 15 min

then any commands and Ctrl-D, or

echo COMMANDS | after 15 min

which does the same.

share|improve this answer
4  
you might want to use "$@" instead of $* -- then arguments containing spaces will be properly quoted –  glenn jackman Apr 25 '11 at 11:12
    
Thanks for the tip. I edited my answer accordingly. I think it doesn't change anything in the context of the at command, bu it's definitely better standard practice. –  Dalker Apr 28 '11 at 8:15
2  
you need to use the quotes around it: specifically "$@" not $@. Only when quoted will bash perform this special expansion: gnu.org/software/bash/manual/bashref.html#Special-Parameters –  glenn jackman Apr 28 '11 at 10:26
    
@glenn, re-edited accordingly. Thanks for the tip, I didn't know that! –  Dalker Apr 28 '11 at 22:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.