Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Unix Perl and Html

by thatguy (Parson)
on Aug 15, 2001 at 23:29 UTC ( #105150=note: print w/ replies, xml ) Need Help??


in reply to Unix Perl and Html

First off, I would not run the printstatus command from your script. This is a big security risk and most likely, the user your webserver uses is not allows sudo access (since it is implicitly defined by the admin).

Now a cronjob running printstatus into a logfile would be better. check out the man page for cron.. something like 0 0 * * * sudo /path/to/printstatus >> /path/to/logfile should work ok.

Depending on the output of printstatus (got a sample?) you could read it in line by line and print out the html using the CGI.pm.. also something like

#!/usr/bin/perl -w use strict; use CGI; my $query=new CGI(); print $query->start_html(-title=>'Printer Status'); open(LOG," /path/to/logfile") || die "Cannot open logfile!: $!\n"; while(<LOG>) { print $query->br,"$_ ",br; } close(LOG); exit;

-p


Comment on Re: Unix Perl and Html
Select or Download Code
Re: Re: Unix Perl and Html
by meccaxlr (Initiate) on Aug 16, 2001 at 17:47 UTC
    Thanks for your help thatguy monk! for security reasons my boss told me not to run a cron job for sudo printstatus. He told me to have my program read form 3 dump files in usr/lsys/printstatus which is the output of printstatus. He said running a sudo would be a bad idea. from there all i have to do is parse the files, any suggestions? Thanks a billion !
      do you have some examples of the output of printstatus? (you can change the names/ips to protect your network, we just want the formatting).

      If the output is a single line per printer you can use my previous example, otherwise there might be some work involved :)

      Update:if the output is something along the lines of

      name display toner level ----------------------------------- printer1 toner low 25% printer2 toner low 1% printer3 etc etc etc

      then this should work ok..

      #!/usr/bin/perl -w use strict; use CGI; my $main=new CGI; print $main->header; print $main->start_html("Printer Status"); open(STATUSFILE," your_outfile") || die "Cannot open logfile!: $!\n"; while(<STATUSFILE>) { chomp; if (! ($_=~ /-----------------------------------/)) { #my ($printer,$display,$toner,$level) = split(/ /, $_) +; my @status = split(/ /, $_); if (($status[0] eq "name") && ($status[1] eq "display" +)) { print "<center><table width=250 border=1><tr a +lign=center>\n"; for (@status) { print "<td><b>$_</b></td>\n"; } print "</tr>\n"; } else { for (@status) { print "<td>$_</td>\n"; } print "</tr>\n"; } } } print "</table>\n"; close(STATUSFILE); exit;

      -p
        I just went into the files my boss specified. When i go into the directory /usr/lsys/printstatus under admin i come up with 3 files 'printstatus.out' 'lpc_status.printing1' and 'lpc_status.printing2'. when i go into printstatus.out there is this nice information window thats something like
        name display toner level
        -----------------------------------
        printer1 toner low 25%
        I just went into the files my boss specified. When i go into the directory /usr/lsys/printstatus under admin i come up with 3 files 'printstatus.out' 'lpc_status.printing1' and 'lpc_status.printing2'. when i go into printstatus.out there is this nice information window thats something like
        name display toner level
        -----------------------------------
        printer1 toner low 25%
        Thank you thatguy monk. Since I am new to perl does this program read from the printstatus file, parse it and send it to a log file??!?!

        I'm just a perl peon

        #!/usr/bin/perl -w use strict; use CGI; my $main=new CGI; print $main->header; print $main->start_html ("Printer Status"); open(usr/lsys/printstatus/printstatus.out ,"logfile.html"); while(<usr/lsys/printstatus/printstatus.out>) { chomp; if (! ($_=~/----------------------------/)) { #my ($printer,$display,$toner,$level) = split(/ /, $_); my @status = split(/ /, $_); if (($status[0] eq "name") && ($status[1] eq "display")) { print "<center><table width=250 border=1><tr align=center> +\n"; for (@status) { print "<td><b>$_</b></td>\n"; } print "</tr>\n"; } } } print "</table>\n"; close (usr/lsys/printstatus/printstatus.out); exit;
        Would this be an accurate representation of this program? Did i substitute the correct variables?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://105150]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2014-10-21 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (105 votes), past polls