Perl - run sub routine for list of devices


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl - run sub routine for list of devices
# 1  
Old 10-25-2010
Perl - run sub routine for list of devices

Hi,

Can anyone please correct the script such that it run on all the devices in the devicelist.txt file.

The problem is when the script runs it only reads the first device in the list, configures the device and exists.




Script:
Quote:
$username="username";
$password="pass";
$enapass="enable";

my $filepath="D:\\scripts\\"."devicelist.txt";
use Net::Telnet::Cisco;
open (FILE, "$filepath");
@list=(<FILE>);
close(FILE);

foreach (@list) {
$host=shift @list;
chomp ($host);
print "$host \n";
&DEVICE_TELNET;
}

sub DEVICE_TELNET {
$session = Net::Telnet::Cisco->new(Host => $host);
$session->login($username,$password);
if ($session->enable($enapass) ) {
@output = $session->cmd('conf t');
@output = $session->cmd('logging 10.1.1.1');
print "Configured Logging server: @output\n";
}
$session->close;
}
The devicelist.txt:
device.crs
device2.ptd
device3.xyz
# 2  
Old 10-26-2010
Change the line in to the script and try. It will process the each devices in the devicelist.txt
Code:
$host=shift @list;

to
Code:
$host=$_;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. UNIX for Beginners Questions & Answers

ARP and Bonjour to build list of user devices

Hi, I want to build a list of the devices that are connected to my network and refresh that list every 10th minute (using an RPi with Raspbian). The host names are obtained by using Bonjour which is easily installed by: sudo apt-get install libnss-mdns To build the list manually, I do like... (2 Replies)
Discussion started by: Zooma
2 Replies

3. Shell Programming and Scripting

PERL: Calling a sub routine from another module - help!!!

Hi, I am an occasional PERL user. I am trying to call a sub routine (passing parameters) in perl module from a driver .pl file. I have been "tinkering" for a while now and have confused myself. Could someone please look at the code below and spot where I am going wrong. testPerl.pl ... (0 Replies)
Discussion started by: chris01010
0 Replies

4. Shell Programming and Scripting

Perl: connect to network devices, run set of commands

I am trying to write a script for my own use that will allow me to connect to network devices, then run a set of commands. I start with a list of ips in a text file. Each ip is on its own line. I start with a second file of commands. Each command on one line. for illustration .. the cmd.txt... (2 Replies)
Discussion started by: popeye
2 Replies

5. Shell Programming and Scripting

how to run an already made script run against a list of ip addresses solaris 8 question

how to run an already developed script run against a list of ip addresses solaris 8 question. the script goes away and check traffic information, for example check_GE-VLANStats-P3 1.1.1.1 and returns the results ok. how do I run this against an ip list? i.e a list of 30 ip addresses (26 Replies)
Discussion started by: llcooljatt
26 Replies

6. Shell Programming and Scripting

Perl - Call a sub routine in a command

Hi all I have written a simple perl script that has different options i.e. myscript -l -p etc i have it so when it runs without any switches it runs a subroutine called nvrm_norm i want to be able to do a -p option and run pall -w -f and then called the subruotine pall is... (1 Reply)
Discussion started by: ab52
1 Replies

7. Shell Programming and Scripting

Run SQL command for a list of devices

Hi Please help me to resolve. Question: I can run this command to change the mode of a device with id=500 as below dbc "select device mode=3 where id=500;" How can i run the same query with a file contaning n number of ids ? file1.txt 12 234 34 500 34 45 Thanks in... (3 Replies)
Discussion started by: sureshcisco
3 Replies

8. HP-UX

list of devices

Hi, I need to rediracte all the names of the devices (only disks) to a file. Thanks:confused: (3 Replies)
Discussion started by: yoavbe
3 Replies

9. UNIX for Dummies Questions & Answers

passthrough devices vs. named devices

I am having trouble understanding the difference between a passthrough device and a named device and when you would use one or the other to access equipment. As an example, we have a tape library and giving the command "camcontrol devlist" gives the following output: akx# camcontrol... (1 Reply)
Discussion started by: thumper
1 Replies

10. Shell Programming and Scripting

Perl: Run perl script in the current process

I have a question regarding running perl in the current process. I shall demonstrate with an example. Look at this. sh-2.05b$ pwd /tmp sh-2.05b$ cat test.sh #! /bin/sh cd /etc sh-2.05b$ ./test.sh sh-2.05b$ pwd /tmp sh-2.05b$ . ./test.sh sh-2.05b$ pwd /etc sh-2.05b$ So... (10 Replies)
Discussion started by: vino
10 Replies
Login or Register to Ask a Question