Replacing value in a file on all remote systems.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing value in a file on all remote systems.
# 1  
Old 03-28-2012
Replacing value in a file on all remote systems.

Hello All,

I want to replace a value of a string in a file on all the remote systems. The file is /opt/adapter/Adapter/snmp/conf/snmpd.conf and the parameter to be replaces if "rocommunity" for which current value is "public" and wish to change it to "sp1der".

i did trying it through sed, but not sure how do i do it all systems. Also there are other strings in file which has a value as "public" which should not be replaced.

Please advice.

Last edited by DukeNuke2; 03-28-2012 at 04:23 AM..
# 2  
Old 03-28-2012
Setting up the public key authentication, then just perform your replacement within a loop!
# 3  
Old 03-28-2012
The public key authorization is already there. can you please what needs to be used in script to achieve this. Thanks in advance.

-Siddhesh
# 4  
Old 03-28-2012
Quote:
Originally Posted by Siddheshk
The public key authorization is already there. can you please what needs to be used in script to achieve this. Thanks in advance.

-Siddhesh
Locating all your remote servers' ip addresses in ip_file one per line!
Code:
for ipaddr in $(cat ip_file); do
     ssh ${ipaddr} "sed -i '/rocommunity/s/public/sp1der/' /opt/adapter/Adapter/snmp/conf/snmpd.conf"
done

# 5  
Old 03-28-2012
Hello,

Bases on the give code, i have written the script. is this correct?

Code:
#!/bin/bash

#########################################################################################################
# Shellscript   :       rocommunity_change.sh - To change the community string 
# Version       :       V1.0
# Owner         :       Siddhesh Khavnekar <siddhesh.khavnekar@mobixell.com>
# Date          :       2012-03-28
# Category      :       Files Management
#########################################################################################################
# Description   :       This scipt will change rocommuniy from snmpd.conf on all nodes
# IP_LIST       :     Locating all your remote servers' ip addresses in ip_file one per line!
#########################################################################################################

#Defining Variable
#------------------------
IP_LIST=<path_to_file>

for ipaddr in $(cat IP_FILE); do
     ssh ${ipaddr} "sed -i '/rocommunity/s/public/sp1der/' /opt/adapter/Adapter/snmp/conf/snmpd.conf"
done

exit 0

Could you please confirm.

-Siddhesh

---------- Post updated at 09:23 PM ---------- Previous update was at 08:31 PM ----------




---------- Post updated at 10:27 PM ---------- Previous update was at 09:23 PM ----------

Hello All,

The above mentioned script worked well. but i have few other requirements on this.

1.Our script should take the IP of servers from a text file (we already have the solution for this in above script)customer have all together 36 nodes.

2.Script should be able to copy the script file on all the other nodes, taking IP from the text file.(ip_list file)

3.rocommunity should be prompted, so that user can input their string, shouldn't be hardcoded. In the above script it directly replaces with sed.

4.Log should be generated out of this, so that they can track it for any errors. (We can include echo commands to get this)

5. And at the end this script must have ability to perform the start/stop/restart from the single server.

Here is the basic code i have written till now which covers point 1, 4 and 5 points. please help

Code:
#!/bin/bash

#########################################################################################################
# Shellscript   :       rocommunity_change.sh - To change the community string 
# Version       :       V1.0
# Owner         :       Siddhesh Khavnekar <siddhesh.khavnekar@mobixell.com>
# Date          :       2012-03-28
# Category      :       Files Management
#########################################################################################################
# Description   :       This scipt will change rocommuniy from snmpd.conf on all nodes
# IP_LIST       :     Locating all your remote servers' ip addresses in ip_file one per line!
#########################################################################################################

#Defining Variable
#------------------------
IP_LIST=/root/IP_LIST
ADAPTER_HOME=/opt/adapter
BACKUP_DIR=/var/tmp
DATE=`date +%Y%m%d%H%M%S`
LOG=/root/community_logs

#Backing Up Orginal Files
#-------------------------
echo "Backing up the original configuration file to $BACKUP_DIR" > $LOG.$DATE
cp -pv $ADAPTER_HOME/Adapter/snmp/conf/snmpd.conf $BACKUP_DIR/snmpd.conf_$(date +%d%b%Y)
cp -pv $ADAPTER_HOME/ManagementTool/conf/MTInternalConfig.properties $BACKUP_DIR/MTInternalConfig.properties_$(date +%d%b%Y)
echo "Orignal Log file back-up done succesfully" >$LOG.$DATE


Need to add code to prompt to change the string in snmpd.conf file. Please advice on the same. here it should promt to change the rocommunity string to sp1der in 
/opt/adapter/Adapter/snmp/conf/snmpd.conf. To be more specific what i want her, It should replace the value of "rocommunity" from public to spider. 
I cannot use sed, bcoz they want to enter the value when it prompts to enter the value. it could be any other value too.

#Verification of changes done.
#-----------------------------
grep -w 'ServerSNMPGetArgs' $ADAPTER_HOME/ManagementTool/conf/MTInternalConfig.properties | grep -w sp1der >> /dev/null
if 
[ $(echo $?) = 0 ]; then
echo "rocommunity string set to sp1der sucessfully in MTInternalConfig.properties for ServerSNMPGetArgs." >> $LOG.$DATE
else
echo "Could not set the rocommunity string to sp1der in MTInternalConfig.properties for ServerSNMPGetArgs. Check the file permission." >> $LOG.$DATE
fi


#Restarting Processes.
#---------------------

snmpd stop 
echo "SNMP process Stopped" >> $LOG.$DATE
sleep 15

snmpd start
echo "SNMP process Started" >> $LOG.$DATE

adapter restart
echo "Adapter restarted" >> $LOG.$DATE

managermenttool restart 
echo "Managementtool Restarted" >> $LOG.$DATE

exit 0

Please advice as this is on priority for me. Thanks in advance.

-Siddhesh

---------- Post updated at 11:23 PM ---------- Previous update was at 10:27 PM ----------

Guys any idea on this. Please reply...

-Siddhesh

Last edited by Siddheshk; 03-28-2012 at 02:31 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to store remote variable from remote cat file ??

I am trying to cat on a file located on remote server and assign it to remote variable. I have both local and remote variables. Running below script from local. test.sh J_NAME=XXX2 J_IP=XXX ssh $J_IP "ps auxw |grep java | grep -v grep |grep $J_NAME | awk '{print ... (2 Replies)
Discussion started by: oraclermanpt
2 Replies

2. UNIX for Advanced & Expert Users

Diff on remote servers file systems

Iam trying to compare two file systems on two hosts basically to check them to be in sync I dont have rsync so trying to use diff Let me know how to do it.... Thanks (3 Replies)
Discussion started by: baanprog
3 Replies

3. SCO

Distinguish between file systems

Hello, is there any command in SCO unix by which I can check if the file system is HTFS or DTFS? Thanks (1 Reply)
Discussion started by: Mick
1 Replies

4. What is on Your Mind?

From Systems Admin to Systems Eng.

I have been wondering how do Systems Administrators do the jump into Systems Engineering? Is it only a matter of time and experience or could I actually help myself get there? Opinions? Books I could read? Thanks a lot for your help! (0 Replies)
Discussion started by: svalenciatech
0 Replies

5. UNIX for Advanced & Expert Users

quick remote health check SAP systems from UNIX commandline

Hi folks Howto do quick remote health check for SAP systems on UNIX commandline? To see if a SAP system is down or in maintenace mode (no login). I am searching something like "tnsping"/Oracle for SAP systems. (2 Replies)
Discussion started by: slashdotweenie
2 Replies

6. SCO

file systems table

hi Where is file systems table stored, I mean which config file from SCO 5.0.6? On linux is in /etc/fstab. (1 Reply)
Discussion started by: ccc
1 Replies

7. UNIX for Advanced & Expert Users

Working with remote Unix files systems from Windows

I am currently using Samba to access remote Unix file systems from Windows. However, it is slow, and I presume insecure in the sense that file contents are transmitted unencrypted. I also wonder if passwords are transmitted in plain text in this protocol or not. For these reasons I am looking for... (2 Replies)
Discussion started by: Bilge
2 Replies

8. UNIX for Dummies Questions & Answers

File systems...

Hello guys, I am new in Unix world. I would like know, how Can I check which type of file system (GPFS, JFS) is on the AIX server. I have AIX 5.1. Could you anyone advice me? Thanks. (4 Replies)
Discussion started by: sokratis
4 Replies

9. UNIX for Advanced & Expert Users

remote file copy across 2 systems (AIX and SCO)

Hello, Pls i need to copy some data from AIX Unix 4.3 to a SCO Openserve 5.0.5 using rcp command. But i keep on having permission error. WHAT IS THE SOLTION OR WHAT COMMAND CAN I USE AGAIN (4 Replies)
Discussion started by: aji
4 Replies

10. UNIX for Dummies Questions & Answers

How can I update a file on 50 systems at once?

I need to update a file that is on 50 different systems at once. In case of planned network outages I would like to overwrite or lock a monitoring script so that it doesn't send notifications. I thought of using a script that ftp 's the updated file to all 50 systems, and then overwrites the... (11 Replies)
Discussion started by: darthur
11 Replies
Login or Register to Ask a Question