Alex Beutel's Blog

Rsync Backup and Batch Printing

October 22nd, 2008 · No Comments

So I haven’t posted in months and have a short break between classes so I wanted to post some scripts that I wrote this year and have been particularly useful.  These are both specific to Duke’s campus, but could easily be extended to other situations.  The first is backup.  In the past few months I had my external hard drive in addition to numerous friend’s entire computer crash.  My dad, just before I left, bought a year long subscription to Mozy, so, nervous about losing all of my data, I thought I’d look into it.  On their very informative site, they give alternatives to their product.  Most of the solutions are rediculous like burn 30 DVDs of all your data each month, but one happens to be a great idea: “Run a cron job of rsync, gzip and mcrypt piped over ssh to your friend’s server over his DSL line.”  I am assuming they were hoping the use of as many acronyms as possible and funny sounding words would deter people from actually reading the statement, but it turns out the basic concept as very easy to implement.  Considering here at Duke each student has 5 gig of server space and I have a server in my room, and its all in-network so its very fast, a simple ssh into the server and running rsync is actually really easy.  I have multiple different rsyncs set up as bash files, such as one for just my schoolwork so I can quickly and frequently back this up and one for my whole harddrive which takes slightly longer.  I also recently set this up for my not-quite as technical friend and gave her a small AppleScript application to run to do the rsync after I set it up.  The only real set up is go onto the server, create a folder (in a private directory) and thats it.  Then configure the script below appropriately and your done.  Here is the script:
tell application “Terminal”
do script with command “rsync -avvvz –delete-after -e ssh /Users/{name}/directoryToBackup/”
end tell
Above we see to simply first reference the name of the folder on your local machine to back up and then username@server address colon folder on server to back up to. And that’s it. Simple and very effective. Thanks Mozy.

The second recent hacked together script I made was a basic way of batch printing. Duke has a system called E-Print, which runs basically by Line Printer Daemon (LPD) to a specific address. Any network printer set up like this. The other key requirement is that I have set my short name on my Mac to my NetID because this short name is the username that is sent through to LPD. If you have this, I create a simple AppleScript application that takes either all selected items or all files in a folder and prints them separately and in duplex with the lpr command. This script is below.
— script was clicked
on run
tell application “Finder”
if selection is {} then
set selection to files in folder of the front window
end if
set finderSelection to selection as alias list
end tell

print {finderSelection}
end run

— script was drag-and-dropped onto
on open (theList)
print (theList)
end open

— print
on print {listOfAliases}
repeat with currentFile in listOfAliases
set currentFileName to POSIX path of currentFile
do shell script (“lpr -o sides=two-sided-long-edge ‘” & currentFileName & “‘”)
end repeat
end print
Or you can download the application here. Place this inside your applications directory, and then in Leopard you can drag it to the toolbar of Finder. I believe you also need to make sure you have the LPD printer set to your default printer. The, you can always easily batch print.

Note: You can also in command line use lp but this will combine all of the documents printed into one item on the print queue, which has its disadvantages in the Duke e-Print system. Also, I need to thank Henrik Nyh whose “Open in Textmate” script I use and worked off of for this.

Tags: AppleScript · Duke · Programming

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment