Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to create a cron that will run one time at a specific time.

For simplicity, how can I create a cron that will run at 11:57PM and print "Hello" to the screen then delete itself? (Cent OS 5)

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

If you need it to run just once, cron is not your tool.

at (1)               - queue, examine or delete jobs for later execution

E.g.:

# at 12:57PM
warning: commands will be executed using /bin/sh
at> echo hello
at> <EOT>
job 2 at Mon Jan  2 12:57:00 2012

(Press ctrl+d when done entering commands)

Scheduling relatively to now

fbh@pinky:~$ at now + 5 min
warning: commands will be executed using /bin/sh
at> echo moo
at> <EOT>
job 5 at Mon Jan  2 06:05:00 2012

And as always, read much more on how to use this tool in the man page for it.

share|improve this answer
add comment

If you use at, the output of the command will be emailed to you. To output text to the current terminal do the following:

echo "echo 'hello' > `tty`" | at 11:57PM
echo "echo 'hello' > `tty`" | at now + 5 minutes

Note that when you use now + x minutes, the execution time will be rounded to the previous minute.

share|improve this answer
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.