Shannon Adams
asked on
Help with shell script
I need to have a script that will automatically log into a network device, reset a port, and exit the network device. The script will be passed three values - ip address, device password and port number. The contents of the shell script are as follows:
telnet $1
<need a carriage return here>
cli
su
$2
admin
reset po = $3
hangup
exit
I am not sure how to add a carriage return after each command. I would appreciate any advice on how to do that and if there are any other commands I need to add to the script.
telnet $1
<need a carriage return here>
cli
su
$2
admin
reset po = $3
hangup
exit
I am not sure how to add a carriage return after each command. I would appreciate any advice on how to do that and if there are any other commands I need to add to the script.
Ignore the above, it is incorrect.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
It could easily be done in perl with the Net::Telnet module, see the simple example below:
#!/usr/bin/perl
use strict;
use Net::Telnet;
my $telnet = new Net::Telnet( Errmode=>'die',
Prompt => '/\# $/i');
$telnet->open('yourhostnam e');
$telnet->login('user', 'password');
print $telnet->cmd('/usr/bin/pwd ; ls');
It could easily be done in perl with the Net::Telnet module, see the simple example below:
#!/usr/bin/perl
use strict;
use Net::Telnet;
my $telnet = new Net::Telnet( Errmode=>'die',
Prompt => '/\# $/i');
$telnet->open('yourhostnam
$telnet->login('user', 'password');
print $telnet->cmd('/usr/bin/pwd
Try
telnet $1 `cat <<EOF
cli
su
$2
admin
reset po = $3
hangup
exit
EOF`