HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell script needed Replace gecos field in /et...
Operating System - HP-UX
1833883
Members
1714
Online
110063
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2009 08:52 PM
05-14-2009 08:52 PM
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2009 09:00 PM
05-14-2009 09:00 PM
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
>>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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2009 09:40 PM
05-14-2009 09:40 PM
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. ;-)
>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. ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2009 09:42 PM
05-14-2009 09:42 PM
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
$5 of course. ;-)
It's right there on passwd(4).
http://docs.hp.com/en/B2355-60130/passwd.4.html
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP