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

Discover more from dannyman.toldme.com

Subscribe now to keep reading and get access to the full archive.

Continue reading