Visit Our UNIX and Linux User Community


Help with Backup Shell Script for Network Device Configuration backup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Backup Shell Script for Network Device Configuration backup
# 1  
Old 10-11-2012
Help with Backup Shell Script for Network Device Configuration backup

HI all, im new to shell scripting. need your guidence for my script. i wrote one script and is attached here

Im explaining the requirement of script.

AIM: Shell script to run automatically as per scheduled and backup few network devices configurations. Script will contain a set of commands which will run on the N/w devices and log the output to a text file and save them to the destination folder in the mentioned path.

I have 100 devices which are mix of Routers, switches, firewalls and packet shapers. Each device has different set of commands. so I plan to make a text files which contain all the device info like device role and ip address of the device, user credentials and Destination path where to save the logs Below are the example of the txt files content.

Device_info.txt
devrole:ipadd
router:10.10.10.1
switch:20.20.20.1
pix:30.30.30.1
netscreen:40.40.40.1
shaper:50.50.50.1

credentials.txt
username:password

Dest_path.txt
/usr/conf_backups/

In simple, script should read Device_info.txt file and connect to the specified device via SSH.
Read “credentials.txt” file for authentication
Check the device role IF condition and jump to the respective loop,
Run the set of commands and log the output to destination folder.
Read “Dest_path.txt” file for Destination path.
Cycle should loop until it complete all the entryes in the Device_info.txt file.


In script I’m creating 5 variables for username($usr), password($passwd), destination path($dest), Device role($dev) and IP address($ip)
Now using script I want to read each line from device_info.text, split the line into two parts, content before and after the delimiter (Smilie and save them into the respective variables. For example, if It read 2nd line(router:10.10.10.1) from the device_info.txt, it should separate the router and send to variable ($dev) and 10.10.10.1 send to variable($IP).

In the code I have to send different commands to different types of devices. So I want to create loops with different set of commands. Then that particular loop should be called by if condition. If IF condition satisfy, should execute the respective commands in the loop.

As im new to scripting, I don’t know how to write if conditions. Need your help and guidance to achieve this. For illustration I just mentioned how my IF condition should be.

If [ “$dev” == ”router” ]
then
execute loop (1)
else
read the next line from the Device_info.txt
fi

If [”$dev” == ”switch” ]
then
execute loop (2)
else
read the next line from the Device_info.txt
fi

If [”$dev” == ”pix” ]
then
execute loop (3)
else
read the next line from the Device_info.txt
fi
………….so on…….

Case {1}
do
{
Send few set of commands to my router
}
Done

Case {2}
do
{
send few set of commands to my switch
}
Done

Case {3}
do
{
send few set of commands to my firewall
log_file $dest
}
Done

Im attaching you my script. Which is having a problem and described below.

if, library functions are defined as below,
#!/usr/bin/expect -f
#!/bin/sh
spawn, expect commands are working but Functions command is not working. for reference plz observe attachmant 11.png file

if, library functions are defined as below
#!/bin/sh
#!/usr/bin/expect -f

Function commands are working but spawn, expect commands are not working. for reference plz observe attachmant 22.png file

if, library functions are defined as below, and no function commands are using in our script, its working fine. for reference plz observe attachmant working.png file this script is my old and basic script

#!/usr/bin/expect -f
#!/bin/sh

Can you suggest me solution or an alternative approach to fulfill my requirement…


And I also want to create one more script for encrypting my credentials.txt file then I can achieve Confidentiality. so while auditing, auditor wil not say anything. This script should work like this. For egg., consider this script name is encrypt.sh when I execute this script,

1. On the screen it Should ask me to input in format “usernameSmilieassword”
2. Read the content and encrypt it.
3. Find the path from where this script is running and write the encrypted content to credentials.text file. If this credentials.txt file is already exists, should over write it, if not create newly.
4. Then in our main script, first read this encrypted content in credentials.txt file, DECRYPT it and write to some file in temp folder.
5. Then read the decrypted txt file from temp folder and execute our old procedure like read the line and split content by the delimiter and save them to respective variables.

Guide me on doing this friends and suggest me if there are any other easy ways to achieve this encryption procedure.

Thank you...Smilie

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.
# 2  
Old 10-11-2012
You might want to reduce the values to either:
  • RDBMS-like lines/rows for easy comparison with sort and comm, and then write a tool to turn them into configuration files or scripts to reinstall the configuration. If you want to change some parameters, modify the file and then feed the lines to the tool. Each line/row might have one value after its description. The storge of a value that appears many places in one cell means generated files are mutually consistent.
  • Write a shadow subtree of host-dirs/files: configuration files or scripts to reinstall the configuration. You can then diff -r saved subtrees with new subtrees.
This way, you can easily detect a changed configuration, and restore it.
# 3  
Old 10-12-2012
Hi DGPickett,

thanks for your responce. aim of my script is SSH to device, execute few commands, capture screen output and log them to a file. like this i have 100+ devices. few devices have different set of commands. so i ve to execute commands with respective to the device type. thats it, im not looking for any thing like comparasion and all.

share if you have any ideas.....Smilie
# 4  
Old 10-12-2012
Well, proceessing the data makes it more interpretable, comparable and usable for reset of values.

You might test commands and dynamically choose commands that are available/effective, like with 'which' and with command-specific trials, so new machines with known commands are adapted to automatically.

To avoid sending a script to 100+ servers, you can either use something like "ssh user@host bash <local_bash_script" or mount a small dir everywhere, once.

Sometimes, having a script called /system.profile on each box that sets up normal variables for that host, which enables the master script to be much simpler. It can have shell functions to provide the same values on every host using local commands, or flag variables to vary the master script.

Gnu parallel is great for doing this very quickly.
This User Gave Thanks to DGPickett For This Post:
# 5  
Old 10-12-2012
Thanks for your sugessions DGPickett....Smilie

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with Backup Shell Script

hello guys i am new and i am using Solaris 8 as operating system. i have some CD and i want to install the data from it. Package and patches. Which command shall i use? thanks (3 Replies)
Discussion started by: moh_abaloo
3 Replies

2. AIX

Backup to a remote tape device. Is it possible?

Hi all The situation is as follows: We need to take an mksysb image from an AIX 6.1 server. From some reason (irrelevant to this discussion) this server does not have access to a local CD-ROM or a tape drive. We do have another server with AIX 6.1 (but different technology level) which got access... (1 Reply)
Discussion started by: abohmeed
1 Replies

3. Shell Programming and Scripting

shell script to backup

Q: script to daily backup all databases in the server, retain only last 4 backps please anyone give me a reply (3 Replies)
Discussion started by: pssooraj72
3 Replies

4. Shell Programming and Scripting

rsync backup mode(--backup) Are there any options to remove backup folders on successful deployment?

Hi Everyone, we are running rsync with --backup mode, Are there any rsync options to remove backup folders on successful deployment? Thanks in adv. (0 Replies)
Discussion started by: MVEERA
0 Replies

5. Shell Programming and Scripting

Help with Backup Shell Script

Hi, I am a linux newbie and I dont have any knowledge on scripting but this is my urgent requirement. I am suppose to write a backup script for 2 of my servers, could someone help me out please. below is my requirement Mail Server 1 : 10.0.0.1 Mail Server 2 : 10.0.0.2 Backup Server... (6 Replies)
Discussion started by: harry289
6 Replies

6. Shell Programming and Scripting

Help with backup shell script

Hello, Need help with a script to backup a configuration file BSD Save the file / Firewall / ConfigFiles to a remote ftp server here is the script # / bin / sh Date = $ (date +% d-% Y-% m-H-M) tar-cvf ConfigFiles.tar / Firewall / ConfigFiles ConfigFiles.tar mv / Firewall-$... (11 Replies)
Discussion started by: telouet
11 Replies

7. Shell Programming and Scripting

Help with backup script in C-shell

Hi I am trying to back up files with cshell script .And I have to pass the size of the files,the backup directory and the file Could you help me with advises ,and am I useing find right thanks #!/bin/csh if( $2 =="") then echo "Please provide correct parameters" echo "corect call is: ... (7 Replies)
Discussion started by: lio123
7 Replies

8. Shell Programming and Scripting

Help with backup shell script

Hello all, I am trying to backup my system database and root filesystem on remote server that is mounted on my system using tar command. For the database, i use (cd /database; tar cvf file.tar .) for the Root filesystem, i use (cd /; tar uEvf file.tar .) both are to be backup on the same... (1 Reply)
Discussion started by: Omoniyi
1 Replies

9. Shell Programming and Scripting

Need help with a backup shell script

am writing my very first shell script and need some assistance. What I need help on is three things in particular. 1) Do I need to use the sleep function after the tar command or does the script know to wait until tar finishes to move on to the next line? 2) Did I populate the variable DATE... (4 Replies)
Discussion started by: rhm54
4 Replies

10. UNIX for Dummies Questions & Answers

cpio backup to a remote device..

Hi, Needing to perform a backup of one system to the tape unit on another system. Why, well because the local tape device is stuffed and I desparately need to have a backup completed successfully sooner rather than not at all. My question is how do I set the below code to allow me to perform... (3 Replies)
Discussion started by: Cameron
3 Replies

Featured Tech Videos