Perl error with $ENV variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl error with $ENV variable
# 1  
Old 03-02-2012
[SOLVED] Perl error with $ENV variable

Hello my friends i have created a perl cgi script to see browser support for text and graphics but $ENV variable is not working ,

Code is:

Code:
#!/usr/bin/perl
#Author Ravinder kumar
# START

use warnings;
$nongraphic = 'lynx|CERN-Linemode|elinks';
$client = $ENV{'HTTP_USER_AGENT'};
$text = "text.html";
$graphics = "graphics.html";

if ($client =~ /$nongraphic/)
{
$htmldoc = $text;
}
else
{
$htmldoc = $graphics;
}
print "Content-type: text/html\n\n";
$docroot = $ENV{'DOCUMENT_ROOT'};
$htmldoc = join ("/",$docroot,$htmldoc);
if(open(HTML,"<",$htmldoc))
{
while (<HTML>)
{
print ;
}
close (HTML);
}
else
{
print "There is some problem\n"
}
exit (0);

#END

--------------------------------------------------------------

OUTPUT IS :

Code:
[root@cent6 cgi-bin]# ./support.pl
Use of uninitialized value $client in pattern match (m//) at ./support.pl line 11.
Content-type: text/html

Use of uninitialized value $docroot in join or string at ./support.pl line 21.

There is some problem
---------------------------------------------------------------
here u can see $ENV variable is not working

any help

Last edited by rink; 03-04-2012 at 03:44 PM.. Reason: please user code tags
# 2  
Old 03-02-2012
BASH is not an HTTP user agent. Smilie HTTP_USER_AGENT is not going to be set when you run it from a commandline! That's a CGI thing.

For testing purposes, you can always set them manually, yourself:

Code:
HTTP_USER_AGENT="angrysnail-5.0" DOCUMENT_ROOT="/path/to/whatever" HTML="whateverfile" ./support.pl

Be very careful with this perl script, by the way. It could potentially be exploited to open arbitrary files, regardless of .htaccess limits.
# 3  
Old 03-03-2012
hello Corona see this script is working by set %ENV variable

Code:
#!/usr/bin/perl

# Author Ravinder kumar
# Cgi script Second part

#Start
print "Content-type: text/html\n\n";

print "<table>";
foreach (sort keys %ENV)
{
  print "<tr><td>$_</td><td>$ENV{$_}</td></tr>\n";
}
print "</table>";

# END

is there any way to set %ENV so i can access individual element by $ENV variable in above script

mean by declaring %ENV variable.

Last edited by Scott; 03-04-2012 at 04:08 PM.. Reason: Code tags
# 4  
Old 03-03-2012
What version of Perl are you using?

tyler_durden
# 5  
Old 03-03-2012
Version is

This is perl, v5.10.1
# 6  
Old 03-03-2012
Quote:
Originally Posted by rink
...this script is working by set %ENV variable
------------------
#!/usr/bin/perl

# Author Ravinder kumar
# Cgi script Second part

#Start
print "Content-type: text/html\n\n";

print "<table>";
foreach (sort keys %ENV)
{
print "<tr><td>$_</td><td>$ENV{$_}</td></tr>\n";
}
print "</table>";

# END
------------------------
...
In the output of this script (your 2nd script), what is the value of the key "HTTP_USER_AGENT" ?

tyler_durden
# 7  
Old 03-04-2012
Output of second script :--------
Code:
   DOCUMENT_ROOT /var/www/html
   GATEWAY_INTERFACE CGI/1.1
   HTTP_ACCEPT text/html, text/plain, text/css, text/sgml, */*;q=0.01
   HTTP_ACCEPT_ENCODING gzip, bzip2
   HTTP_ACCEPT_LANGUAGE en
   HTTP_HOST localhost
   HTTP_USER_AGENT Lynx/2.8.6rel.5 libwww-FM/2.14 SSL-MM/1.4.1
   OpenSSL/1.0.0-fips
   PATH /sbin:/usr/sbin:/bin:/usr/bin
   QUERY_STRING
   REMOTE_ADDR ::1
   REMOTE_PORT 46329
   REQUEST_METHOD GET
   REQUEST_URI /cgi-bin/env.pl
   SCRIPT_FILENAME /var/www/cgi-bin/env.pl
   SCRIPT_NAME /cgi-bin/env.pl
   SERVER_ADDR ::1
   SERVER_ADMIN root@localhost
   SERVER_NAME localhost
   SERVER_PORT 80
   SERVER_PROTOCOL	HTTP/1.1
   SERVER_SIGNATURE	Apache Server at 192.168.3.15 Port 80
   SERVER_SOFTWARE	Apache


Last edited by Scott; 03-04-2012 at 04:09 PM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Treat value of variable as env variable

Hi All, I have a requirement where I have a config file, which contains 2 coulmn.values of first column are environmnet variable, whose value is defined in an environment file. In my script I need to read the config file, and get the value of the config file variable from env file. I... (2 Replies)
Discussion started by: alok2082
2 Replies

2. Web Development

Deny from env=env-variable Does not work

(Above from Apache docs). On my system, using: SetEnvIf User-Agent Mozilla IsBad=1 Order allow,deny Allow from all Deny from env=IsBad ...I see that environment variable is set (using phpinfo()) but the page is still served. No errors in the Apache logs. (1 Reply)
Discussion started by: gnurob
1 Replies

3. Shell Programming and Scripting

Perl Csh - setenv ENV change environment variable

I have 3 programs, 1 in perl, 2 in csh: call them perl1, csh1 and run.ol I need perl1 to set csh1 variable NOLOG_qsub = "" I need perl1 to run, run.ol run.ol takes the executable and input and outputs to output run.ol#!/bin/csh -f # run.ol executable input output perl1 should... (1 Reply)
Discussion started by: austinj
1 Replies

4. Solaris

Env variable in solaris

Hi, Am installing SAP on Solaris 10. How to set env variables permanently? Reg (0 Replies)
Discussion started by: daggupati453
0 Replies

5. Shell Programming and Scripting

Env variable

Hello, I want to cange env variable on SunOS. I tried: export GONGA=$GONGA:/users/BANK1/basic/queues/SARON_SPACE1 it changed it only localy for my session. when i opened a new session (telnet etc') the old value exist. How can I change it to effact all sessions. Thanks. (2 Replies)
Discussion started by: LiorAmitai
2 Replies

6. Shell Programming and Scripting

get env variable from last script

I have 2 scripts t2.sh calls t1.sh. I need to get the vaule of a env variable from t1.sh /tmp/test$ cat t1.sh #!/bin/sh INSTANCE="font/fc-cache" export INSTANCE svcadm disable ${INSTANCE} /tmp/test$ cat t2.sh #!/bin/sh . /tmp/test/t1.sh echo ${INSTANCE} The above works... (9 Replies)
Discussion started by: honglus
9 Replies

7. Shell Programming and Scripting

Doubt on ENV variable

Question 1: If I set ENV=$HOME/myenvprofile.ksh, will my script get executed when ever I login to my with KSH. My doubt is we used to put this in .profile of our home directory. SO when ever I login will it executed? QUestion 2: If I set ENV=`echo "hi"` or 'echo "hi" ', what would be the output.... (0 Replies)
Discussion started by: ramkrix
0 Replies

8. UNIX for Dummies Questions & Answers

Env Variable

Hi, I have a doubt on Environment variable. I want to know where and when the envirnment variables are defined? Thanks & Regards, Siba (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

9. UNIX for Dummies Questions & Answers

PWD env variable

Could you please tell me, which process / file is responsible for the setting of PWD env variable in Solaris Thanks (1 Reply)
Discussion started by: chaandana
1 Replies

10. Shell Programming and Scripting

bash env variable containing @

I want to set a bash env variable which has @ in its name, for example, @YOGESH@ may i know how do i do this? (4 Replies)
Discussion started by: Yogesh Sawant
4 Replies
Login or Register to Ask a Question