I Think i finaly got this working, and id like to share what i did, and what i wanted it to do.
I wanted my printers to power on, once they got a print job sent to then.
I didnt want to bother with cups.. The lprng seemed to be an op solution
i was inspired by this.
http://chezphil.org/slugpower/but decided to use this device instead.
http://sispmctl.sourceforge.net/So heres what i did.
1. Created sispmctl as rpm, and installed it.
2. Chmod 4755 /usr/local/bin/sispmctl , to make it run as root, when lp called it
3. create a crontab entry, to run every 5 minutes, turning the printers of again
3.1 mkdir /etc/e-smith/templates-custom/etc/crontab -p
3.2 cp /etc/e-smith/templates/etc/crontab/* /etc/e-smith/templates-custom/etc/crontab
3.3 create the file
vi /etc/e-smith/templates-custom/etc/crontab/printerOff
add the following
#/etc/e-smith/templates-custom/etc/crontab/printerOff
{
$OUT .= "\n";
$OUT .= "# smeserver-printerPower Turn of printers\n";
$OUT .= "*/5\t*\t*\t*\t*\troot\t/usr/local/bin/printeroff\n";
}
3.4 expand-template /etc/crontab
Right.
Now we have a crontab, that every 5 minutes will try to run the /usr/local/bin/printeroff
so well create that.
4.1 vi /usr/local/bin/printeroff
4.2 add the folowing
#!/bin/bash
#/usr/local/bin/printeroff
# program to shut printers of
# runs every file in dir
dir="/tmp/PrinterOFF/"
for file in $dir
do
$file
done
4.3 chmod +x /usr/local/bin/printeroff
Now we have a running printeroff command.
that looks for the printeroff files in /tmp/PrinterOFF
so we do a
4.4 mkdir /tmp/PrinterOFF -p
Still were not turning printers on automaticly, were only shutting them down.
So heres the exiting bit.
lets create a filter, that will turn the printer on
5.1 vi /usr/libexec/filters/startprint
#!/bin/bash
#/usr/libexec/filters/startprint
# simple shell filter to start printers
# on turning on, it creates a shutdown file as well
#hardcoded path
paht=/tmp/PrinterOFF
args=("$@")
#exec printer on string
${args[0]} ${args[1]}
# create the printer OFF dir, that cron is looking in
mkdir $paht -p
#make sure we dont shut THIS printer off by deleting turn off files
rm $paht/${args[4]}* -f
#create the new shutdown stamp time
tim=$(date --date=${args[5]}' minutes' +%k%M)
# and the new filename will be
filename=$paht/${args[4]}
# now write the off file
# This is a bash script
echo "#!/bin/sh" >$filename
echo "# this file will shutdown a printer." >>$filename
echo "# it will be deleted, if a new printjob i activated." >>$filename
echo "" >>$filename
# now we will test, if it is time to shut the printer off
echo "if [ "$tim$" -le \`date +%k%M\` ]" >>$filename
echo "then">>$filename
# now we enter the shutdown command
echo ${args[2]} ${args[3]} >>$filename
# and then we delete ourself
echo "rm -f "$filename >>$filename
# and we end the if command
echo "fi" >>$filename
# make it executable
chmod +x $filename
# now send the print job on to the next quewe
exec cat
5.2 chmod +x /usr/libexec/filters/startprint
so.
Now we have the code, to turn on the printer, we just need to get lprng to do it.
I had a bit of trouble here, since lprng checks to see if the printer is ok, BEFORE running any filters ( witch is bad when i want the filter to turn the printer on).
The solution, all be it not a very nice one, was to create a dummy queue. So lets do that.
Now I had an existing printer, so ill try to show what i did, so i didnt have to redo all of the clients.
my printer is named hplaser.
I created a queue called hplaserdonotuse.
This created the following /etc/printcap file
#------------------------------------------------------------
# !!DO NOT MODIFY THIS FILE!!
#
# Manual changes will be lost when this file is regenerated.
#
# Please read the developer's guide, which is available
# at http://www.contribs.org/development/
#
# Copyright (C) 1999-2006 Mitel Networks Corporation
#------------------------------------------------------------
#--------------------------------------------------
# Example printcap entry:
#
# hplaser|HP Laser 5:\
# :server:\
# :mx#0:\
# :sh:\
# :ff_separator=false:\
# :sd=/var/spool/lpd/hplaser:\
# :lp=/dev/lp0:
#--------------------------------------------------
hplaser|sorthvid A4:\
:server:\
:mx#0:\
:sh:\
:ff_separator=false:\
:sd=/var/spool/lpd/hplaser:\
:lp=/dev/usb/lp0:
hplaserdontuse|DummyForPOWERON:\
:server:\
:mx#0:\
:sh:\
:ff_separator=false:\
:sd=/var/spool/lpd/hplaserdontuse:\
:lp=/dev/usb/lp0:
An now we need to change this so that the flow will be
hplaser->filter->hplaserdontuse
The filter, will have to be told som options.
and i settled on the following.
filter_options=sispmctl -qo2 sispmctl -qf2 hplaser 15
This tells it to use sispmctl as start command, use -qo2 as parametere to this.
Use sispmctl as the shutdown command, use -qf2 as the switch to this
Call the file hplaser, so i can see witch queue were using, and wait for 15 minutes, before you power down again.
Ill show the new printcap in the next post.
Edit: applied code formating to relevant fragments to improve readability