Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # 'expect' is needed
- #
- # Use special user on ftp-server for running this script.
- # It's a better and tested way, but you can also make some little changes in code
- # and use different servers for running scripts and conf-files collecting.
- # 1. Place this script in some directory inside homedir (~/bin for example)
- # 2. Create additional list of your cisco-routers (see SETTINGS part for additional info)
- # 3. Create additional directory for saved conf-files (~/config for example)
- # 4. Fill SETTINGS part correctly
- # 5. If you use enable password - uncomment "UNCOMMENT IF ENABLE" part of script
- #
- # Run the script and you will see the *.tgz with all conf-files in homedir.
- use English;
- # SETTINGS
- $ftpserver = '192.168.1.100';
- $FTPUSER="ftpuser";
- $FTPPASS="ftppassword";
- # cisco user
- $USER="ciscouser";
- $PASS_USER="ciscopassword";
- # ENABLE password
- $PASS_ENABLE="enablepass";
- # directory with this file
- $DIR="/home/ftpuser/bin";
- # directory inside 'ftpuser' homedir where script will place configs
- $CONFDIR='config';
- # cisco list in format:
- # cisco1-name::192.168.1.1
- # cisco2-name::192.168.1.2 etc.
- $filename = "$DIR/cisco.list";
- # CODE
- system("cd $DIR");
- system("rm -f ./temp.sh");
- ($DAY, $MONTH, $YEAR) = (localtime)[3,4,5];
- $MONTH=$MONTH+1;
- $YEAR=$YEAR+1900;
- open DATA, $filename or die "Unable to open $filename: $!";
- while (<DATA>) {
- chomp;
- ($name, $ip) = split(/::/);
- system("cd $DIR");
- system("echo '#!/usr/bin/expect -f' >> $DIR/temp.sh");
- system("echo spawn telnet $ip >> $DIR/temp.sh");
- system("echo expect 'Username: ' >> $DIR/temp.sh");
- system("echo send '\"$USER\n\"' >> $DIR/temp.sh");
- system("echo expect 'Password: ' >> $DIR/temp.sh");
- system("echo send '\"$PASS_USER\n\"' >> $DIR/temp.sh");
- # UNCOMMENT IF ENABLE
- # system("echo send \"enable\\n\" >> $DIR/temp.sh");
- # system("echo expect 'Password: ' >> $DIR/temp.sh");
- # system("echo send \"$PASS_ENABLE\\n\" >> $DIR/temp.sh");
- system("echo expect '\\#' >> $DIR/temp.sh");
- system("echo send '\"copy running-config ftp://$FTPUSER:$FTPPASS\@$ftpserver/$CONFDIR/config-$name-($YEAR-$MONTH-$DAY)\n\n\n\n\"' >> $DIR/temp.sh");
- system("echo expect '\\#' >> $DIR/temp.sh");
- system("echo send '\"exit\n\"' >> $DIR/temp.sh");
- system("chmod 755 $DIR/temp.sh");
- system("$DIR/temp.sh");
- system("rm -f $DIR/temp.sh");
- }
- close DATA;
- system("rm -f $DIR/temp.sh");
- system("tar -czvf ~/$YEAR-$MONTH-$DAY.tgz ~/$CONFDIR/ && rm -rf ~/$CONFDIR/**");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement