in reply to For each loop through mysql db to run Net::Telnet command
Do not use function prototypes. This turns out to be a bad idea although it looks familiar from other languages. There is reason for them, but this is not it.
Once you have done that, I could move the main loop part of
the code to the front and put the subs at the end.
I recoded one sub for you.
#---------------------------------------------------------------- # Execute a command on a Zhone device - recoded***** #---------------------------------------------------------------- sub zhoneCommand { my ($command,$session) = @_; #<- look at this line for I/F my @output=$session->cmd(String => "$command", Errmode => 'return'); chomp @output; return(@output); } #-------------- I would use fetchall_arrayref for a small, simple result set like this +. You get a reference to an array of server_host's. Then just iterate over that array. #--------------------- # loop through the servers table to pull data for each server my $sql = $dbc->prepare("SELECT server_host FROM servers"); my $result = $sql->execute(); or die "Unable to execute sql: $sql->errstr"; my $host_array_ref = $result->fetchall_arrayref() or die "can't get a +rray ref! $sql->errstr"; foreach my $rowref (@$host_array_ref) { my ($host) = @$rowref; print "Calling telenet stuff for $host\n"; #a little debugging o +utput is fine # call your telenet routine on this host }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: For each loop through mysql db to run Net::Telnet command
by jay83 (Novice) on Nov 08, 2022 at 18:02 UTC | |
by 1nickt (Canon) on Nov 08, 2022 at 20:14 UTC | |
by jay83 (Novice) on Nov 14, 2022 at 13:13 UTC | |
by Marshall (Canon) on Nov 10, 2022 at 15:36 UTC | |
by jay83 (Novice) on Nov 14, 2022 at 13:15 UTC |