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 logsBelow are the example of the txt files content.
·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 ( 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 “usernameassword” 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...
Moderator's Comments:
Please use code tags next time for your code and data.
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)
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)
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)
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)
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)
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)
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)
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)
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)