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;
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
$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;