We want to comment the specific line in fstab
file that contained the relevant UUID
number
Example:
Disk=sde
UUID_STRING=` blkid | grep $Disk | awk '{print $2}' `
echo $UUID_STRING
UUID="86d58af9-801b-4c25-b59d-80b52b4acc61"
sed -e "/$UUID_STRING/ s/^#*/#/" -i /etc/fstab
but from /etc/fstab
, the line - UUID=86d58af9-801b-4c25-b59d-80b52b4acc61 /data/sde ext4 defaults,noatime 0 0
- not commentated
more /etc/fstab
UUID=cb47ad8e-5b90-4ddc-97f5-2c0fa1f1b7e7 /data/sdc ext4 defaults,noatime 0 0
UUID=169da708-3c48-4306-beba-95dab722d3ab /data/sdd ext4 defaults,noatime 0 0
UUID=86d58af9-801b-4c25-b59d-80b52b4acc61 /data/sde ext4 defaults,noatime 0 0
UUID=640e2c41-d5c6-4e02-beb9-714ec99e16e2 /data/sdf ext4 defaults,noatime 0 0
UUID=58a8cddf-7ce9-431c-bb71-f4f44c8d62a5 /data/sdg ext4 defaults,noatime 0 0
UUID=6779c108-f74b-4a05-8faf-cf8752844c53 /data/sdh ext4 defaults,noatime 0 0
UUID=3c2352f6-df8e-4b14-b6c0-60caaef0dce0 /data/sdi ext4 defaults,noatime 0 0
UUID=ba59e473-d856-4c8b-a3be-4bfc40009f0d /data/sdb ext4 defaults,noatime 0 0
is it possible to ignore the --> "
? in sed command - sed -e "/$UUID_STRING/ s/^#*/#/" -i /etc/fstab
other solution could be as
uuid_capture=` echo $UUID_STRING | sed s'/"/ /g' | awk '{print $NF}' `
sed -e "/$uuid_capture/ s/^#*/#/" -i /etc/fstab
more /etc/fstab
UUID=cb47ad8e-5b90-4ddc-97f5-2c0fa1f1b7e7 /grid/sdc ext4 defaults,noatime 0 0
UUID=169da708-3c48-4306-beba-95dab722d3ab /grid/sdd ext4 defaults,noatime 0 0
#UUID=86d58af9-801b-4c25-b59d-80b52b4acc61 /grid/sde ext4 defaults,noatime 0 0
UUID=640e2c41-d5c6-4e02-beb9-714ec99e16e2 /grid/sdf ext4 defaults,noatime 0 0
UUID=58a8cddf-7ce9-431c-bb71-f4f44c8d62a5 /grid/sdg ext4 defaults,noatime 0 0
UUID=6779c108-f74b-4a05-8faf-cf8752844c53 /grid/sdh ext4 defaults,noatime 0 0
UUID=3c2352f6-df8e-4b14-b6c0-60caaef0dce0 /grid/sdi ext4 defaults,noatime 0 0
UUID=ba59e473-d856-4c8b-a3be-4bfc40009f0d /grid/sdb ext4 defaults,noatime 0 0
sed -i 's/.*'"$Disk"'/#&/' /etc/fstab
? – Cyrus Jan 25 '22 at 21:02blkid -s UUID -o value /dev/sde
– Cyrus Jan 25 '22 at 21:19