Operating System - Linux
1751885 Members
5431 Online
108783 Solutions
New Discussion юеВ

Re: one-liner to add mount options to two mount points in fstab

 
SOLVED
Go to solution
Sean M.
Advisor

one-liner to add mount options to two mount points in fstab

I'm trying to add nodev and nosuid mount options for temporary mount points in /etc/fstab. Is there a one-liner that could be used to do the following?:

Before:

LABEL=/tmp1 /tmp ext3 defaults,acl 1 2

LABEL=/tmp1 /tmp ext3 defaults,acl,nodev,nosuid 1 2

I'm trying to do it using sed -i, but I am unable to get it give me desired output. Sorry if this is a duplicate, but I couldn't find a thread for exactly what I'm trying to do.
6 REPLIES 6
Sean M.
Advisor

Re: one-liner to add mount options to two mount points in fstab

It might make a difference on the command, so:

there is 1 tab between label and mount, and 2 tabs between mount point and file system type.
Steven Schweda
Honored Contributor
Solution

Re: one-liner to add mount options to two mount points in fstab

Any reason not to use a simple substitution?

$ echo 'LABEL=/tmp1 /tmp ext3 defaults,acl 1 2' | \
> sed -e 's/,acl/,acl,nodev,nosuid/'
LABEL=/tmp1 /tmp ext3 defaults,acl,nodev,nosuid 1 2

With my weak psychic powers, I can't see the
file. Are there any instances of ",acl"
which you don't wish to change?

> It might make a difference [...]

Not here, I believe.
Sean M.
Advisor

Re: one-liner to add mount options to two mount points in fstab

Below is my current fstab. I only want to do it for the tmp and var mount point to fix an audit finding.

LABEL=/1 / ext3 defaults,acl 1 1
/dev/cciss/c0d1p5 /backup ext3 defaults 1 2
LABEL=/boot1 /boot ext3 defaults,acl 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
LABEL=/home1 /home ext3 defaults,acl 1 2
LABEL=/opt1 /opt ext3 defaults,acl 1 2
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
LABEL=/tmp1 /tmp ext3 defaults,acl 1 2
LABEL=/usr1 /usr ext3 defaults,acl 1 2
LABEL=/var1 /var ext3 defaults,acl 1 2
LABEL=SW-cciss/c0d0p2 swap swap defaults,acl 0 0

Thanks
Steven Schweda
Honored Contributor

Re: one-liner to add mount options to two mount points in fstab

> [...] I only want to do it for the tmp and
> var mount point [...]

My regular expression skill is near-minimal,
but you might try something like:

sed -e '/\/tmp\|\/var/s/,acl/,acl,nodev,nosuid/'

$ cat fstab
LABEL=/tmp1 /tmp ext3 defaults,acl 1 2
LABEL=/usr1 /usr ext3 defaults,acl 1 2
LABEL=/var1 /var ext3 defaults,acl 1 2
LABEL=SW-cciss/c0d0p2 swap swap defaults,acl 0 0

$ sed -e '/\/tmp\|\/var/s/,acl/,acl,nodev,nosuid/' < fstab
LABEL=/tmp1 /tmp ext3 defaults,acl,nodev,nosuid 1 2
LABEL=/usr1 /usr ext3 defaults,acl 1 2
LABEL=/var1 /var ext3 defaults,acl,nodev,nosuid 1 2
LABEL=SW-cciss/c0d0p2 swap swap defaults,acl 0 0


man sed

Adding some white space around those names
might be wise, especially if you expect plain
"/tmp" or "/var" to match too many things.
Sean M.
Advisor

Re: one-liner to add mount options to two mount points in fstab

Thanks!

I don't have to worry about multiple tmp\var mount points so your sed line will work perfectly.
Sean M.
Advisor

Re: one-liner to add mount options to two mount points in fstab

closed