Gossamer Forum
Home : General : Perl Programming :

Perl and unix commands - passing variables.

Quote Reply
Perl and unix commands - passing variables.
I want a form where a user can input a printer name (ie. STL-001) and get the status of that printer.

I can do the following by hard coding the printer name and it does return a status to a web page. My question is how can I make the printer name a variable to pass into the unix command of `lpstat -p STL-001`

#!/usr/bin/perl

$|= 1;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Fcntl;
use Shell;
use strict;

# print html header, doc root, PERL verions and module info
print "content-type: text/html \n\n";

my $prnt_stat = `lpstat -p STL-001`;

print "<br><br>";
print "<b>Printer Status: </b> $prnt_stat";

# print "<br><br>";
# my $foo = echo("howdy", "funny", "world");
# print $foo;

# print "<br><br>";
# my $passwd = cat("/etc/passwd");
# print $passwd;
exit;




Returns to my webpage:


Printer Status: printer STL-001 is idle. enabled since Jul 15 15:27 2003. available.
Quote Reply
Re: [Kuberski] Perl and unix commands - passing variables. In reply to
Code:
#!/usr/bin/perl

$|= 1;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Fcntl;
use Shell;
use strict;
use CGI;

my $IN = new CGI;

# print html header, doc root, PERL verions and module info
print "content-type: text/html \n\n";

my $_printer = $IN->param('printer') || "STL-001";
my $query = "lpstat -p $printer";
my $prnt_stat = `$query`;


print "<br><br>";
print "<b>Printer Status: </b> $prnt_stat";

# print "<br><br>";
# my $foo = echo("howdy", "funny", "world");
# print $foo;

# print "<br><br>";
# my $passwd = cat("/etc/passwd");
# print $passwd;
exit;

...bits in red are added, or modified.

Hope that helps.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Perl and unix commands - passing variables. In reply to
Remove the redundant code first though =)
Quote Reply
Re: [Paul] Perl and unix commands - passing variables. In reply to
I wasn't sure if he still needed it in there Tongue

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Perl and unix commands - passing variables. In reply to
It is extremely insecure to make system calls with unchecked user input....

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Perl and unix commands - passing variables. In reply to
I was simply proving how he could do it. I'm not gonna write loads of error checking for him too Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Perl and unix commands - passing variables. In reply to
Nice excuse =)
Quote Reply
Re: [Paul] Perl and unix commands - passing variables. In reply to
I thought so Tongue