Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: For each loop through mysql db to run Net::Telnet command

by jay83 (Novice)
on Nov 14, 2022 at 13:19 UTC ( [id://11148175]=note: print w/replies, xml ) Need Help??


in reply to For each loop through mysql db to run Net::Telnet command

Thank you all - here is the working code segment:

#################################### //code this below to loop through + all the servers with DB connection, join all results into one array +#################################### my $dsn = "DBI:mysql:table:localhost"; my $username = "username"; my $password = 'password'; my $dbc = DBI->connect($dsn, $username, $password) or die "Unable to c +onnect to mysql: $DBI::errstr\n"; #//loop through the servers table to pull data for each server my $sql = $dbc->prepare("SELECT server_host FROM server_test"); $sql->execute() or die "Unable to execute sql: $sql->errstr"; my $host_array_ref = $sql->fetchall_arrayref() or die "can't get array + ref! $sql->errstr"; foreach my $rowref (@$host_array_ref) { my ($host) = @$rowref; print "Calling telenet stuff for $host\n"; #a little debugging ou +tput is fine # call your telnet routine on this host my $device = $host; my $user = "user"; my $password = "password"; STDOUT->autoflush; die "Unable to telnet to device\n" if (! (my $session=zhoneConnect($de +vice))); die "unable to login to device\n" if (! zhoneLogin($session, $user, $p +assword)); zhoneCommand($session, "timeout off"); zhoneCommand($session, "setline 0"); $session->prompt('/\n\rAUTO>\s*/'); zhoneCommand($session, "setprompt session AUTO>\r"); my @output=zhoneCommand($session, "bridge show"); for (@output) { print "$_\n"; } zhoneDisconnect($session); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148175]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-18 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found