Avatar of Jason Yu
Jason Yu
Flag for United States of America asked on

how to bulk update /etc/fstab file

I have about 50 linux servers need updating the records inside /etc/fstab file.

The only change is from  those that have netapp:/vol/vol_orabackup mounted to svm2nfs:/vol_orabackup.

The original is netapp:/vol_orabackup      /orabackup       nfs     rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,noac,vers=3,timeo=600

The destination is svm2nfs:/vol_orabackup      /orabackup       nfs     rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,noac,vers=3,timeo=600

 Can I write a script and run the script to update it?

I heard about some configuration update tool, is there a tool I can use to manage all configuration files on linux. thank you.
Linux DistributionsLinuxScripting Languages

Avatar of undefined
Last Comment
gheist

8/22/2022 - Mon
Jason Yu

ASKER
I got the following lines as below, please give your advise:

#!/bin/bash

DIRECTORY=/orabackup2

if [ ! -d "$DIRECTORY" ]; then
  # Control will enter here if $DIRECTORY doesn't exist.
  mkdir /orabackup2
fi


#Create temporary file with new line in place

cat /etc/fstab | sed -e "s/netapp\:\/vol/svm2nfs/" > /tmp/test1

#Copy the new file over the original file

mv /tmp/test1 /etc/fstab

Open in new window

SOLUTION
Duncan Roe

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
gheist

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Duncan Roe

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jason Yu

ASKER
Yes, netapp is just a share name on netapp storage device.
SOLUTION
gheist

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
gheist

sed (
sed -i s/netapp:\/vol/svm2nfs/g /etc/fstab
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Duncan Roe

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
gheist

Yes, but add -i parameter to edit in-place...