Portál AbcLinuxu, 12. května 2025 07:55
#!/usr/bin/perl ##-varibles use Expect; $ssh = "/usr/bin/ssh -v"; $router = "$ARGV[0]"; $txtfile = "$ARGV[1]"; #-get username/password open(PS,"/etc/monitor.passwd"); while ("<"PS">") { chomp; ($usernm,$pass) = split(/\|\|/, $_); } close(PS); $command = "$ssh -l $usernm $router"; #-connect to router. $ssh = Expect->spawn("$command"); $ssh->log_stdout(0); #-send password. if ($ssh->expect(undef, "password:")) { print $ssh "$pass\r"; } #-send command. open( FILE, "< $txtfile" ) or die; if ($ssh->expect(undef, ">")) { while ($cmd = "<"FILE">") { print $ssh "$cmd\r"; $ssh->expect(undef, ">"); } } close FILE; print $ssh "/quit\r";
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.