Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Unix Perl and Html

by meccaxlr (Initiate)
on Aug 16, 2001 at 17:47 UTC ( [id://105368]=note: print w/replies, xml ) Need Help??


in reply to Re: Unix Perl and Html
in thread Unix Perl and Html

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 !

Replies are listed 'Best First'.
Re: Re: Re: Unix Perl and Html
by thatguy (Parson) on Aug 16, 2001 at 17:51 UTC
    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

        Yes that should be the name of the printstatus file.

        when i work on SOPW questions i use the monk's name as the name of the files involved.. I forgot to change that to something else..
        -p

      #!/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?
        that's close. The filehandle is a reference to the file, so instead of having the path to the file, it needs to be a keyword or decriptive word. Then inside the quotes you need to put the filename (with path).

        Here's what it should look like:

        #!/usr/bin/perl -w use strict; use CGI; # start new cgi process my $main=new CGI; # print html headers print $main->header; # print html tags and add title print $main->start_html ("Printer Status"); # open /usr/lsys/printstatus/printstatus.out under filehandle LOGFIL +E open(LOGFILE," /usr/lsys/printstatus/printstatus.out"); # while there is data in LOGFILE while(<LOGFILE>) { # remove newlines (\n) from input chomp; # if the imput is not the divider line if (! ($_=~/----------------------------/)) { # put the contents of the current line into the array @status # we are spliting on the space so that every word seperated by # a space becomes a new element in the array my @status = split(/ /, $_); # if the first element of @status does not equal 'name' (the t +itle header if (($status[0] eq "name") && ($status[1] eq "display")) { # print the start of the table print "<center><table width=250 border=1><tr align=center> +\n"; # for each element in @status for (@status) { # print a new table cell print "<td><b>$_</b></td>\n"; } # close the table row print "</tr>\n"; } } } # close the table print "</table>\n"; # close LOGFILE close (LOGFILE); exit;
        if you are curious about some of the commands/functions that are used, type perlfunc:NameOfFunction in the super search.
        -p

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found