dannyman.toldme.com


Technical

Unix Trick: Block-and-Page

Well, I hope to give some cool narrative of the big move to San Francisco, the awesomeness of my new pad, and the joy joy experience of a hip new job, but for now, I’ll share a little Unix trick.

You ever had a job to do that consisted of issuing a time-consuming command, waiting a long time, then issuing the next time-consuming command, waiting a long time . . . meanwhile, you wander off and focus on other things and the time-consuming command has completed but long ago you stopped paying any attention whatever?

Well, what I do, is ask Unix to page me when the command completes. “Hey, boss! Wake up! Time to look at me again!”

This is pretty easy to rig up. For example, this morning I had to copy a series of CD-ROMs, swapping between each copy, so my command looks like:
cp -rp /media/cdrom/* 10.1 && echo "copy done" | mail -s "copy done" [email protected]

If you don’t already “get” it, I’ll explain:

cp -rp /media/cdrom/* 10.1
This is the time-consuming command: copy the contents of the CD-ROM to a directory.
&&
This means “if the last command completed successfully, execute the next command.” Like a conditional operator in your favorite programming language. Of course, in this context, ;; is probably smarter, as it means “after the last command terminates, successfully or otherwise, execute the next command.” (Even if the copy screws up, I still want to know, right?)
echo "copy done" | mail -s "copy done" [email protected]
Say “copy done” and send that to the mail command, with the subject “copy done”, and send that to [email protected]

Hrmmm, my pager just went off. I guess I am done posting for now!

Read More

Next:
Previous:
Categories: Technical
Possibly-Related Posts
Notes: Make Ubuntu GUI Less Annoying
Electronic Recipe Rant
JavaScript Hack: Hide an Element on a Page
Experiment: April on $10/day

  • Nick

    Ha ha Danny … you’re still helping me and you don’t work here anymore!

  • http://www.HaidongJi.com Ji Village News

    Great trick! Keep ‘em coming.

    It’s in my Google Notebook now :)

  • Fee

    I like that… what other mail command you have. maybe one for a block echo command that need to be redirected to you work e-mail

  • Pingback: The Ji Village News » View and kill processes in Linux and Solaris

  • Russ

    Under Mac OS X I sometimes do a variation on this using the ‘say’ command line utility that speaks whatever text you give it. For example:
    cp -rp /media/cdrom/* 10.1 ; say “copy finished”
    Useful for when you’ve got the window in the background or you’re near your computer at least.