[cups.general] scripting around lpadmin

Norm Jacobs naj at snapcon.com
Fri Jan 21 22:39:40 PST 2011


On 01/21/11 10:23 PM, Paul wrote:
> I've written a ksh script that parses through a CSV and then builds printers in both a Database (for the application) and in CUPS.  Now that I have functionality built, i've started primate proofing it and hit a brick wall.  I'm trying to redirect output of the lpadmin commmand so I can see if it failed (i.e. CUPS was stopped) but for the life of me I can't get it to re-direct.  Things i've tried:
> CStat=$(lpadmin -ptestprinter -D"This is a Test" -vsocket://testprinter:9100 -E)
> lpadmin -ptestprinter -D"This is a Test" -vsocket://testprinter:9100 -E>>  test.txt
> lpadmin>>test.txt -ptestprinter -D"This is a Test" -vsocket://testprinter:9100 -E
> lpadmin -ptestprinter -D"This is a Test" -vsocket://testprinter:9100 -E | everyconcievable command I could think
>
> but it always is null.
>
> Anyone else have an idea on how to get it to redirect?  the message it reports back at least if CUPS is not running is:
> lpadmin: Unable to connect to server: Connection refused
>
> While I can code around other ways to ensure CUPS is running, I was more hoping to just make a catch all to cover anyway that lpadmin may fail.  basically if it returns anything...it failed, else, worked

You might check the exit code from lpadmin to determine if it failed and 
error messages are usually sent to standard error, not standard output.

     # lpadmin -p test -v /dev/null >/tmp/output 2>/tmp/errors
     # [[ $? -ne 0 ]] && echo "failed"

 > redirects stdout to /tmp/output
   2> redirects stderr to /tmp/errors
   $? is the exit code of the previous command

Hopefully this gets you further.

     -Norm






More information about the cups mailing list