LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Help in scripting related to router information gathering. (https://www.linuxquestions.org/questions/linux-networking-3/help-in-scripting-related-to-router-information-gathering-425684/)

kharerohit 03-17-2006 04:39 AM

Help in scripting related to router information gathering.
 
I have written script for gathering information from the router shown as below:

#!/bin/sh

USERID=
PWD=
PWD1=
dir=`pwd`
ip=
intface=
DATE=`date +'%m%d'`
Time=`date +'%H%M'`
(echo "$USERID";\
echo "$PWD";\
echo "en";\
echo "$PWD1";\
echo "sh ip cache flow";\
echo "q";\
sleep 30 )| telnet $ip > $dir/info$ip$DATE$Time.txt

But through this I can run only single command or set of commands in same file at one logging into router.

Can anyone help how to get the result from the router for different commands in different file without logging again and again into router?

pcweirdo 03-17-2006 05:37 AM

I'd use Perl for this, though there are other languages for the job.

eg.
Code:

#!/bin/sh

USERID=
PWD=
PWD1=
dir=`pwd`
ip=
intface=
DATE=`date +'%m%d'`
Time=`date +'%H%M'`
(echo "$USERID";\
echo "$PWD";\
echo "en";\
echo "$PWD1";\
echo "sh ip cache flow";\
echo "q";\
echo "sh ip pat does not understand this router";\
echo "q";\
sleep 30 )| telnet $ip > perl -e '<STDIN>;open FILEONE, > $dir/info$ip$DATE$Time.txt; print FILEONE, $_; <STDIN>;open FILEONE, > $dir/info$ip$DATE$Time.txt2; print FILEONE, $_; <STDIN>;open FILEONE, > $dir/info$ip$DATE$Time.txt3; print FILEONE, $_; '

The Perl bit is far too long and could probably be condensed into some kind of loop. I've printed a line to each file, those files having the same name but with a number appended. Watch the syntax errors!

-pcweirdo.


All times are GMT -5. The time now is 08:02 PM.