Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

expect.pm question

Status
Not open for further replies.

cab00se

Technical User
Oct 22, 2004
4
US
I am trying to get a cgi script to interact with a remote server. The script logs into the server, runs a command, and prints the output of the command to a webpage. At least it's supposed to.. I am using the expect module to log into the remote system via ssh, my problem is that when I log in I cannot run commands because it says that my TERM environment variable is not set. I turned logging on and this is the output I get from the script. Any help will be appreciated.



Password: Last login: Wed Jan 5 14:50:48 2005 from sc3-*.*.*.*.charter-stl.com This machine is property of whitacres.net Only authorized personnel are allowed to connect.
-bash-2.05b$ echo $TERM dumb
-bash-2.05b$ top -b -n1 TERM environment variable not set. -bash-2.05b$

top -b -n1
TERM environment variable not set.
-bash-2.05b

Here is the script:

#!/usr/bin/perl -w
use Expect;
use CGI qw:)standard);
$Expect::Log_Stdout =1;

print header;
($ssh = Expect->spawn("ssh user\@host.net\r"));
($ssh->expect(20,"Password:"));
print $ssh "*******\r";
($ssh->expect(10, "\$ "));
print $ssh "echo \$TERM\r";
($ssh->expect(10, "\$ "));
print $ssh "top -b -n1\r";
($ssh->expect(10, "\$ "));
$top = $ssh->before();
print $ssh "exit\r";

print start_html ('test');
print "<PRE>";
print $top;
print "</PRE>";
print end_html;
 
on the remote system or the system running the script?
 
I didn't finish that last post, I added that line to the /etc/profile on the system running the script. However it ddidn't seem to work properly. Another odd thing to note, is that when I su to the user my webserver is running the script as, and run it command line it works fine. It is only when run from the cgi script that it loses it's environment variables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top