How to replace value in fstab file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace value in fstab file?
# 1  
Old 11-22-2018
How to replace value in fstab file?

Hi,
I am looking to replace value (fifth and sixth ) column to "0 0" in /etc/fstab file by scripting.
can any one please help me.


/dev/VolGroup00/tmp /tmp ext3 defaults 1 1
# 2  
Old 11-22-2018
Scripting changes to vital system files is very, very dangerous. Be sure you have a plan B in case that goes badly.

If I had to, I'd be paranoid and verify every part of the line.

Code:
awk '(NF==6)&&($1=="/dev/VolGroup00/tmp")&&($2=="/tmp")&&($3=="ext3")&&($4=="defaults"){ print $1,$2,$3,$4,1,1; next } 1' /etc/fstab > /tmp/fstab
# Uncomment once you've tested and are sure /tmp/fstab is what you want it to be.
# use cat, not mv, because mv may change permissions and ownership
# cat /tmp/fstab > /etc/fstab
rm -f /tmp/fstab


Last edited by Corona688; 11-22-2018 at 04:13 PM..
# 3  
Old 11-23-2018
May be add few steps like take a backup of file. and validate file.

First to make backup
Code:
[ ! -d "/root/fstab_backup" ] && mkdir /root/fstab_backup
cat /etc/fstab > /root/fstab_backup/fstab.${date +%j_%y}.BACKUP

Now to test it
Code:
mount -fav

Just make sure to check man pages on system to validate. Also run each command by itself and validate.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Create zip file from root owned fstab

I want to zip up my fstab file for backup purposes. This does not work because of permission issues. cd /etc/ zip -u fstab.zip fstab Can I use this with zip? echo xxx | sudo -S or change fstab owner to me? (3 Replies)
Discussion started by: drew77
3 Replies

2. Linux

/etc/fstab entries

Hi, Can anyone explain why we use defaults 0 0 in fstab and what does 0 inidicate 10.250.104.50:/home/u /home/u nfs defaults 0 0 Thanks in advance Muzaffar (3 Replies)
Discussion started by: muzaffar.k
3 Replies

3. Red Hat

Mount /etc/fstab

Can you please help me mount below filesystem in fstab ( I have rhel 5 ) as the line is long - it is not taking as single line How can break this in 2 line and act as one ....please help ... (4 Replies)
Discussion started by: saurabh84g
4 Replies

4. Red Hat

Effects of /etc/fstab file!

Hi Folks! I accidentally overwrote in /etc/fstab file. Can you guys please tell me, what impact it would have created, when I restarted the machine(RHEL6). I executed this command : # blkid /dev/vda5 > /etc/fstab (17 Replies)
Discussion started by: nixhead
17 Replies

5. Ubuntu

fstab question

I have created a thumbdrive with a bootable version of Ubuntu 10.04 LTS, it uses Grub legacy. One of the issues I have is that everytime I boot a new system from the thumbdrive, it writes entries for the partitions in the fstab. Consequently, when I boot another system, the OS reads the fstab... (2 Replies)
Discussion started by: stumpyuk
2 Replies

6. UNIX for Dummies Questions & Answers

fstab

hi , i'm creating a shell script using fstab for my project of last year, i wonder you can help me to know what is the command allow me to get the list of unmounted partitions. thanks (4 Replies)
Discussion started by: Linux001
4 Replies

7. Red Hat

edit/write the /etc/fstab file

Hi, I comment out some vol group in fstab accidentally. I also comment the swap space in /etc/fstab But I cannot edit /remove it back by using vi /etc/fstab again in init 1 and init 6 . The file system /etc/fstab is read -only . I cannot chmod ..... What can I do in order to recover it ... (2 Replies)
Discussion started by: chuikingman
2 Replies

8. UNIX for Dummies Questions & Answers

FSTAB Problem

Hello, I transferred a machine from a tape back into a virtual machine. I created several paritions so I could xfter the date into them and made sda1 the active one. When I try and boot the VM it does not work. I used KNOPPIX to create the partitions and transfer the information from the tape... (1 Reply)
Discussion started by: mojoman
1 Replies

9. UNIX for Dummies Questions & Answers

fstab question

Folks; Please be patient with this issue when you read it. I know it's a little tricky. I have a new share created on my SUSE 10 box. I'm trying to edit the /etc/fstab file or find a way to make this share needs no authentication. The reason for that is we're using an outside application to... (3 Replies)
Discussion started by: Katkota
3 Replies

10. Linux

/etc/fstab

I've created a new drive and i've added it to my fstab file but on startup it will not mount. here is how i put it into my fstab file, is that right? /dev/hdb2 /disk2a ext3 defaults 1 2 (6 Replies)
Discussion started by: byblyk
6 Replies
Login or Register to Ask a Question