Operating System - HP-UX
1833883 Members
1714 Online
110063 Solutions
New Discussion

Re: Shell script needed Replace gecos field in /etc/passwd

 

Shell script needed Replace gecos field in /etc/passwd

Hi,

Iam into learning process of shell scripting, I need script to replace gecos field in /etc/passwd
im trying to read 2 files list1 and list2(list of userIDs) and compare with $1 field of /etc/passwd,if contents of list1 matches the /etc/passwd then and run chuser command to replace gecos field to FunctionlistValue else set ServiceListValue else notfound perform manual

I have figured out something like this:
--------------------
#!/bin/sh
Functionlist="code here"
servicelist="Code here"
if [cat /tmp/list1 $1= cat /etc/passwd $1]
then
echo "Found $1 in list1\\n"
/usr/bin/chuser -R $1 gecos=$Functionlist
fi

if [cat /tmp/list2 $1= cat /etc/passwd $1]
then
echo"Found $1 in list2\\n"
/usr/bin/chuser -R $1 gecos=$servicelist

else
echo "User ID not found Please implement change manually \\n"
exit

please correct my script
3 REPLIES 3
Suraj K Sankari
Honored Contributor

Re: Shell script needed Replace gecos field in /etc/passwd

HI,
>>I need script to replace gecos field in /etc/passwd

Could please let me know in /etc/passwd file where this field is located "gecos"

Suraj
Dennis Handly
Acclaimed Contributor

Re: Shell script needed Replace gecos field in /etc/passwd

(You might want to change your forum name to something that you can use for more than one question.)

>trying to read 2 files list1 and list2 (list of userIDs)

What's in list1? Also UIDs?

Also, there is no such thing as chuser on HP-UX, there is chfn(1) but it prompts.

while read uid; do
/usr/bin/chuser -R $uid gecos="$Functionlist" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Found $uid in list1"
fi
done < /tmp/list1

while read uid; do
/usr/bin/chuser -R $uid gecos="$servicelist" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Found $uid in list2"
else
echo "User ID ($uid) not found Please implement change manually"
fi
done < /tmp/list2

This assumes that the non-existent command chuser sets a bad exit status if $uid doesn't exist.

>Suraj: Could please let me know in /etc/passwd file where this field is located "gecos"

$5 of course. ;-)
Dennis Handly
Acclaimed Contributor

Re: Shell script needed Replace gecos field in /etc/passwd

>Suraj: Could please let me know in /etc/passwd file where this field is located "gecos"

$5 of course. ;-)
It's right there on passwd(4).
http://docs.hp.com/en/B2355-60130/passwd.4.html