Operating System - HP-UX
1832890 Members
2268 Online
110048 Solutions
New Discussion

Ch. 11 Shell Script Needed

 
SOLVED
Go to solution
Andre Harvey
New Member

Ch. 11 Shell Script Needed

I'm studying the "HP Certified: HPUX System Administration" book and the answer to the review question #6 in Ch. 11 is missing. It sounds simple but I'm new and need some help. The question reads as follows:

Previously all users were using the Bourne shell. The administration has changed the policy and now everyone is asked to use the POSIX shell. Write a program that changes the shell of all users from /usr/bin/old/sh to /usr/bin/sh.

6 REPLIES 6
Mark Grant
Honored Contributor
Solution

Re: Ch. 11 Shell Script Needed

sed "s/\/usr\/bin\/old\/sh/\/usr\/bin\/sh/" /etc/passwd > /etc/passwd.new && mv /etc/passwd.new /etc/passwd

Looks like it will work!
Never preceed any demonstration with anything more predictive than "watch this"
Andre Harvey
New Member

Re: Ch. 11 Shell Script Needed

Thanks!
Thork
New Member

Re: Ch. 11 Shell Script Needed

Dear Scott,

If I understand you, you need a routing that replace in the passwd file the string â /usr/bin/old/shâ to â /usr/bin/shâ . Try whit this one:

for i in `cat /etc/passwd`
do
echo $i | awk '{ sub("/usr/bin/old/sh","usr/bin/sh"); print $0 }' >> /tmp/newpasswd
done

this routing dosenâ t work if the lines in the file has bl
Manish Srivastava
Trusted Contributor

Re: Ch. 11 Shell Script Needed

Hi,

I agree with Mark only one more addition:

sed "s/\/usr\/bin\/old\/sh$/\/usr\/bin\/sh/" /etc/passwd > /etc/passwd.new && mv /etc/passwd.new /etc/passwd

add the "$" after the \/usr\/bin\/old\/sh$ to make sure that only the last item of each entry is changed.

manish.
RAC_1
Honored Contributor

Re: Ch. 11 Shell Script Needed

for i in `cut -d : -f1`
do
/usr/sbin/usermod -s /usr/bin/sh $i
done

Anil
There is no substitute to HARDWORK
RAC_1
Honored Contributor

Re: Ch. 11 Shell Script Needed

Typo in my earlier post.

cp /etc/passwd /etc/passwd.bak
for i in `cut -d : -f1 /etc/passwd`
do
/usr/sbin/usermod -s /usr/bin/sh $i
done

Anil
There is no substitute to HARDWORK