betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

09 June 2008

Shell fun: at(1) and leave(1)

Time is on your side!

Want to send a mail message at a pre-specified time? Want to be reminded when to leave from work? People have worked with the Unix shell for many years now and they have developed the tools to make things like that easy. Here is how to do these things with at and leave...

First our mail example. There is a nice command called at, which allows things to be run "at a specified time". You can of course view it's man page with man at, but here is a quick rundown: First, you specify the time you want a command to be run as the commands argument, in 24 hour time (without the ":"), like at 2330. You can also give it a relative time as in at + 6 hours or at 0130 + 3 days. The actual command that will be run is expected on the "standard input", so after running the at command, you can type it in (or when in a script, you can pipe it in) and type ^D (control-D) when you're done:

at + 6 hours
mail -s 'Mail from the past'
This mail...

        ... comes from the past.
          (6 hours past, to be exact.)
commands will be executed using /bin/ksh
job 1213010520.c at Mon Jun  9 18:22:00 2008

Of course this isn't very comfortable, so you might want to prepare the message in advance in a text file and pipe it in:

at + 1 hours
cat todo_while_im_away.txt | mail -s "I'm on my way"
commands will be executed using /bin/ksh
job 1213016478.c at Mon Jun  9 13:34:00 2008

... and now leave!

Which maybe reminds you that you need a reminder to stop that concentrated hacking session, zoom out of "the zone" and get going, because you gonna miss your train. No problem, just tell your shell at what time you will have to leave.

The usage of leave (read the man page with man leave again) is even simpler:

leave 1800
# or even:
leave +0030

In the first case you want to leave at 6pm, in the second case you want "just 30 minutes more" of sweet hacking time.

How does leave remind you? It will "beep" your terminal and print "You have to leave in 5 minutes." and then "Just one more minute!", followed by "Time to leave!" on your terminal. It doesn't wait until you enter a command to get the next terminal prompt, it writes over your input right now. Leave will continue prompting, until you kill its process or log out (thus killing its process too).

Do I see that?

leave was obviously written in a time when people worked in one shell window alone. For a long time I didn't gt it to be much useful any more. But nowadays I use screen(1) a lot and have an irssi session open for IRC (and AIM through bitlbee). Inside screen, I will be visibly and audibly reminded, that there is a "bell in window 3"... and I can go and check and see that I should leave in 5 minutes. So "screen" makes "leave" useful again.

Posted by betabug at 10:41 | Comments (1) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Hacking and Beach day | Main | Fussball und Regen >>
Re: Shell fun: at(1) and leave(1)

I guess I know at because one day someone said something about it in a manual, and because it appears as a reference when you look in date/calendar/cron related things.

But I didn't know about leave. Interesting and funny :)

I guess I should write the modern and Mac way of at and leave :) They're quite useful, when the software "slaps" you with a huge banner in your screen (note, not in your GNU screen).

And god save the GNU screen!

Posted by: graffic at June 11,2008 01:40
You can trackback to:
There are no trackbacks.