Using sed to comment out line in /etc/vfstab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using sed to comment out line in /etc/vfstab
# 1  
Old 07-14-2009
Using sed to comment out line in /etc/vfstab

I am running a script remotely to do the following

1. Kill all processes by a user
2. Uninstall certain packages
3. FTP over a new file
4. Kill a ldap process that is not allowing my /devdsk/c0t0d0s7 slice to un-mount
5. Unmount /h
6. comment out the slice in vfstab
7. newfs the un-mounted slice
8. un-comment the slice in vfstab
9. reboot

here is my code

Code:
#!/bin/bash
echo "Killing all TESTUSER Processes"
kill -9 `ps -fu TESTUSER | awk 'NR != 1 {print $2}'`
sleep 2
cd /var/sadm/pkg
echo "Gathering all installed ABC pacakges"
pkginfo -c ABC |awk '{print $2}' > /tmp/list
sleep 2
echo "Removing all ABC pacakges"
for x in `cat /tmp/list`; do rm $x/install/postremove; touch $x/install/postremove; pkgrm -nv $x; done
echo "FTP over new managesoft index.xml"
HOST='testserver'
USER='tester'
PASSWD='xxxxxxx'
FILE='/var/tmp/index.xml'

ftp -n -i $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
mget $FILE
quit
END_SCRIPT
quit

echo "Moving new index.xml"
mv /var/tmp/index.xml /var/lib/managesoft/live/index/machine

echo "killing /h ldap processes"
ps -aef |grep ldap |awk '{print $2}' >/tmp/ldap
for x in `cat /tmp/ldap`; do kill -9 $x; done

the above works fine without any problems below is where I have problems inserting # into /etc/vfstab
Code:
echo "Commenting out /dev/dsk/c0t0d0s7 from /etc/vfstab"
sed s/"\/dev\/dsk\/c0t0d0s7"/"#\/dev\/dsk\/c0t0d0s7"/g  /etc/vfstab

echo "un mounting /h"
umount -f /dev/rdsk/c0t0d0s7

echo "Creating a new /h"

newfs /dev/dsk/c0t0d0s7 < /dev/null

echo "Un commenitng"
sed /"#\/dev\/dsk\/c0t0d0s7"/"\/dev\/dsk\/c0t0d0s7"/g /etc/vfstab

init 6

# 2  
Old 07-14-2009
I put your line /dev/dsk/c0t0d0s7 in a testfile and tried running your code
Code:
sed s/"\/dev\/dsk\/c0t0d0s7"/"#\/dev\/dsk\/c0t0d0s7"/g testfile

It worked...
what error are you getting??
# 3  
Old 07-14-2009
never mind I got my for inserting it into the vfstab

Code:
sed -i 's|\(^/dev/dsk/c0t0d0s7\)|#\1|' /etc/vfstab

how do I reverse the code now?
Code:
sed -i 's|\(^#/dev/dsk/c0t0d0s7\)|\1|' /etc/vfstab



---------- Post updated at 01:29 AM ---------- Previous update was at 01:28 AM ----------

do a more /etc/vfstab and it is not commented it. It appears to be not sure why
# 4  
Old 07-14-2009
sed does not make changes in the file...
You have to redirect it to a new file and then do a mv
# 5  
Old 07-14-2009
Use single quotes around sed scripts.

Code:
sed 's!^/dev/dsk/c0t0d0s7!#\1!' /etc/vfstab

Also you might want to use -i option of sed.
# 6  
Old 07-14-2009
so at the end of the sed code do
Code:
 >> /etc/vfstab.new

Code:
mv vfstab.new vfstab

?
# 7  
Old 07-14-2009
Looks like a i missed a few posts. -i is not supported on all operating systems. Try gsed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Comment out crontab using sed command

I am trying to comment out the crontab entries using sed. I want to comment it out for a particular environment say '/mypath/scripts/'. Using the full path as pattern, it is working. but using variable it is not working. i have tried double quotes too. but no luck! $ crontab -l ... (3 Replies)
Discussion started by: SKhan
3 Replies

2. Shell Programming and Scripting

comment a line of the patterns is a the beginning of the line

I need to comment the lines starting with pattern "exclude" or "exclude=". If the work exclude comes at any other part, ignore it. Also, ignore, excludes, excluded etc. Ie only comment the line starting with exclude. File contents. exclude exclude= hi I am excluded excludes excludes= ... (9 Replies)
Discussion started by: anil510
9 Replies

3. Shell Programming and Scripting

sed adding/removing comment in crontab

I have a requirement where I want to add a comment '#' in my crontab, run a process, than remove the '#' I added. Example cron #5,10 * * * * ls -lt /tmp 10,5 * * * * ls -lt /var I would like to be able use sed or awk to add a '#' at the begining of each line. After the command... (4 Replies)
Discussion started by: BeefStu
4 Replies

4. Shell Programming and Scripting

Comment a line with SED

I have around 25 hosts and each hosts has 4 instance of jboss and 4 different ip attached to it . I need to make some changes to the startup scripts. Any tips appreciated. I have total of 100 instances which bind to 100 different ip address based on instance name. For example File1 ... (1 Reply)
Discussion started by: gubbu
1 Replies

5. Shell Programming and Scripting

how to remove line from /etc/vfstab using shell / perl

Hi, could someone help me on this i want to remove line from /etc/vfstab in the system how to do that it is rite now like this /dev/vx/dsk/appdg1/mytestvol /dev/vx/rdsk/appdg1/mytestvol /mytest vxfs 3 no largefiles /dev/vx/dsk/appdg1/mytestvol1 ... (2 Replies)
Discussion started by: tarunn.dubeyy
2 Replies

6. Shell Programming and Scripting

How To comment a line where a word exists

Hi All Can u help me.. My problem is comment (#) a line where a word exists in that line sample: cat /tmp/file.txt monitor 192.168.1.11 Copying files in current directory 1 monitor 192.168.1.1 Copying files in current directory 2 monitor 192.168.1.12 Copying files in current... (2 Replies)
Discussion started by: darren_j
2 Replies

7. Shell Programming and Scripting

Help using SED to comment XML elements

I'm trying to write a script to help automate some VERY tedious manual tasks. I have groups of fairly large XML files (~3mb+) that I need to edit. I need to look through the files and parse the XML looking for a certain flag contained in a field. If I find this flag (an integer value) I need... (4 Replies)
Discussion started by: J-Hon
4 Replies

8. Shell Programming and Scripting

get rid of xml comment by grep or sed

Hi, I would like to get rid of all comment in an xml file by grep or sed command: The content seem like this: <!-- ab cd ef gh ij kl --> Anyone can help? Thanks and Regards (3 Replies)
Discussion started by: RonLii
3 Replies

9. UNIX for Dummies Questions & Answers

how to replace a text of line with a comment line

I want to replace this line : "test compare visible] true" and make it "#test compare visible] true". How can I do it ? And it should be checked in many sub folder files also. (6 Replies)
Discussion started by: manoj.b
6 Replies

10. Shell Programming and Scripting

sed/awk to insert comment at defined line number

Hi there, may someone easily help me on this : I want to insert a text in a specific line number like : linenumb2start=`cat memory_map.dld | nl -ba | egrep -i "label" | cut -f1` line2insert=`expr $linenumb2start + 2` and now I need to replace something like {} with {comment} at... (8 Replies)
Discussion started by: homefp
8 Replies
Login or Register to Ask a Question