Skip to content

Instantly share code, notes, and snippets.

@rbochet
Forked from rbochet/printer.sh
Created December 26, 2010 10:47
Show Gist options
  • Save rbochet/755341 to your computer and use it in GitHub Desktop.
Save rbochet/755341 to your computer and use it in GitHub Desktop.
Shell script for printer cron (w/ lock)
#!/bin/bash
# Romain Bochet
# Use as a cron
# Print all the files included in a folder with lp, and move them in another folder.
# Use absolute path (mandatory for crons)
SOURCE="/home/dropbox/print/"
DONE="/home/romain/printed/"
LOCK="/tmp/printerlock"
# Test if another thread is running this script
if [ -f $LOCK ]
then
exit
fi
touch $LOCK
for FILE in `ls $SOURCE`
do
/usr/bin/lp $FILE
/bin/mv "$SOURCE$FILE" $DONE
done
rm $LOCK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment