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" pager@example.com

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" pager@example.com
Say “copy done” and send that to the mail command, with the subject “copy done”, and send that to pager@example.com.

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

Read More

Next:
Previous:
Categories: Technical
Possibly-Related Posts

Responses

July 27th, 2006

Nick

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

July 27th, 2006

Ji Village News

Great trick! Keep ’em coming.

It’s in my Google Notebook now :)

August 11th, 2006

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

August 11th, 2006

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

[…] This is more of note to myself as I am doing more work on Linux and Solaris environment. Hope you find it helpful. Let’s just say I have a long, long way to go before I reach Dannyman’s level. […]

August 16th, 2006

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.

Comment

Leave a comment . . .

Tiny Print:

  1. For private messages, e-mail me: dannyman@toldme.com.
  2. You must provide an e-mail address.
  3. You can use a bogus e-mail address, but I like to know who you are.
  4. I will not spam you. I will not publish or share your e-mail address.
  5. First-time commenters will be held for review.
  6. You can use these HTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>