Koozali.org: home of the SME Server

Printers that power up them selves

Offline browsem

  • *
  • 16
  • +0/-0
    • My robotics company
Printers that power up them selves
« on: February 20, 2012, 02:10:02 PM »
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

Code: [Select]
#/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
Code: [Select]
#!/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

Code: [Select]
#!/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
Code: [Select]
#------------------------------------------------------------
#              !!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
« Last Edit: February 20, 2012, 08:45:20 PM by cactus »
Why work.
Thats what Vba, Python, robots and COMOS is fore.
I can program just about anything.
Need anything done ?

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Printers that power up them selves
« Reply #1 on: February 20, 2012, 06:46:54 PM »
Ill show the new printcap in the next post.

Please post stuff like this in the wiki - it's likely to be lost in the forum. Thanks.

Offline browsem

  • *
  • 16
  • +0/-0
    • My robotics company
Re: Printers that power up them selves
« Reply #2 on: February 20, 2012, 09:09:24 PM »
I will, just as soon as it really works.
I just found out that i have a problem with the numbering of /dev/usb/lp*.
If there is more than one printer, the printer thats turned on first, gets the number /dev/usb/lp0
So ill need to do another script, that runs with the hotplug, that then links /dev/usb/lprightone to /dev/pr0 or /dev/pr1 .
And again, we need to delete this link, when we close the printer.
Therefore i must first find the hotplug.d
Why work.
Thats what Vba, Python, robots and COMOS is fore.
I can program just about anything.
Need anything done ?

Offline browsem

  • *
  • 16
  • +0/-0
    • My robotics company
Re: Printers that power up them selves
« Reply #3 on: February 20, 2012, 10:08:45 PM »
ok, so heres the deal.
It seemes that udev, can be... fixed, to give a printer the same node every time.
Basicly telling me that i can make my hplaser /dev/usb/lp0, and my oki /dev/usb/lp1 every time.
Ill work on that, and some better way of creating the dummyports.
That should be doable from templates
Why work.
Thats what Vba, Python, robots and COMOS is fore.
I can program just about anything.
Need anything done ?

Offline browsem

  • *
  • 16
  • +0/-0
    • My robotics company
Re: Printers that power up them selves
« Reply #4 on: February 21, 2012, 10:46:43 AM »
Yeah it works.
Please forget about creating the dummy queue.. i think ill get the template to do this.
So now i have the following.
1. a filter and scripts to turn printer on /off
2. a script creating an udev rule, to make sure were printing to the right printer, when we turn on/off
3. im working on the template scripts, to get this working
What im missing.
1. I would dearly like to get a set of properties in the printer setup. Something like (TurnOnCmd, TOC_Option, TurnoFfCommand, TFC_Option, Ontime in minutes), right now im using a conf file, that ISNT auto generated.
proberbly placed under a checkbox or something...
2. someone to tell me how to get the scripts in a rpm, so we can all enjoy :-)
3. someone to help make a wiki page for me. Still havent learnt.
Br
Why work.
Thats what Vba, Python, robots and COMOS is fore.
I can program just about anything.
Need anything done ?

Offline Stefano

  • *
  • 10,836
  • +2/-0
Re: Printers that power up them selves
« Reply #5 on: February 21, 2012, 11:13:08 AM »
2. someone to tell me how to get the scripts in a rpm, so we can all enjoy :-)

read the developer's manual ;-)

Offline browsem

  • *
  • 16
  • +0/-0
    • My robotics company
Re: Printers that power up them selves
« Reply #6 on: February 21, 2012, 11:20:54 AM »
Thx Stefano
I was just about ready to give you a verbal spanking, but then i did read the manual.
and lo and behold.
There it was, in all its glory.
what i hadnt found with google for 3 hours :-D
So my lesson of today RTFM

Btw all:
There was a possibility to add db fragments.
Having learned, that db's are HOLY, i need to ask.
Do i just add what i need, to the database ?
Br Bjarke
Why work.
Thats what Vba, Python, robots and COMOS is fore.
I can program just about anything.
Need anything done ?

Offline browsem

  • *
  • 16
  • +0/-0
    • My robotics company
Re: Printers that power up them selves
« Reply #7 on: February 22, 2012, 11:24:53 AM »
ok.
So i read on and learned a few things.
I tried to do a server panel but i cant get anything but a server error, so ill do a bash thinghy instead, just to get started.
Best
Why work.
Thats what Vba, Python, robots and COMOS is fore.
I can program just about anything.
Need anything done ?

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: Printers that power up them selves
« Reply #8 on: February 22, 2012, 02:28:46 PM »
browsem

Re server manager panel.
I suggest you copy & reuse existing code for other panels, adjust to suit your needs.
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline browsem

  • *
  • 16
  • +0/-0
    • My robotics company
Re: Printers that power up them selves
« Reply #9 on: February 22, 2012, 02:36:50 PM »
Hi mary. Thx. i tryed copying the printer panel, and corespoding /usr/lib/perl5/site_perl/esmith/FormMagick/Panel/printers.pm:
This works but give me no header.
when i start changing the code i get my errors. Specificly i changed printers to printerpower, an then nothing works.
I guess i do something wrong but im not sure what
Why work.
Thats what Vba, Python, robots and COMOS is fore.
I can program just about anything.
Need anything done ?