- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script for /etc/password
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
02-17-2004 09:27 AM
02-17-2004 09:27 AM
I am new at scripting and need help??
I need to modify /etc/password file and compare the username to the username in a flat file if it finds it then replace the comments field in /etc/pasword and populated from a flat file with this string Ex. "C-137h 897 Abu Sassi (HP)".
Thanks for your help in Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2004 09:36 AM
02-17-2004 09:36 AM
Re: script for /etc/password
#!/bin/sh
for name in $(cat mynamefile); do
grep $name /etc/passwd >/dev/null 2>&1
if [ $? ]; then
echo "Modifying $name"
/usr/bin/chfn $user >/dev/null 2>&1 <<-!
$name
C-137h 897 Abu Sassi (HP)
none
none
!
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 03:13 AM
02-18-2004 03:13 AM
Re: script for /etc/password
Thanks for the script. I am still not clear on the text string. I don't want to enter the strings manually; I need the script to pull the info from the flat file. I also not sure if the $user defined in your script.
Thanks for your response
Abu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 03:33 AM
02-18-2004 03:33 AM
Re: script for /etc/password
With the script I posted, you wouldn't be entering anything manually. What does your flat file look like?
e.g.
user1:some comments about user1
user2:some comments about user2
then the script would look like....
#!/bin/sh
for LINE in $(cat mynamefile); do
name=$(echo $LINE|awk -F":" '{print $1}')
comment=$(echo $LINE|awk -F":" '{print $2}')
grep $name /etc/passwd >/dev/null 2>&1
if [ $? ]; then
echo "Modifying $name"
/usr/bin/chfn $name >/dev/null 2>&1 <<-!
$comment
none
none
none
!
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 03:36 AM
02-18-2004 03:36 AM
SolutionI thought my post was missing as it happened quite a few times with this site. Looks like you have a duplicate thread here where you can see my response.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=450853
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 03:45 AM
02-18-2004 03:45 AM
Re: script for /etc/password
for LINE in $(cat mynamefile);do
becomes
cat mynamefile|while read LINE; do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 03:53 AM
02-18-2004 03:53 AM
Re: script for /etc/password
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 04:36 AM
02-18-2004 04:36 AM
Re: script for /etc/password
I'd use an perl or sed and awk script to parse out the fields and redefine the text.. Make sure no one is in SAM changing a user at the time or you'll be jacked..
created a backup of your /etc/passwd file.
If you Want to read STDIN into the comment field via interaction I'd do something like this..
I do like SRI's version.. I will have to try it myself. I do something a bit different on a user by user basis..
echo "Enter User Name:"
read username
grep $username /etc/passwd
export comment `grep $username /etc/passwd |awk -F: '{print $5}'`
echo "Enter New Comment information:"
read comment2
perl -p -i -e s/$comment/$comment2/g /etc/passwd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 04:54 AM
02-18-2004 04:54 AM
Re: script for /etc/password
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 05:09 AM
02-18-2004 05:09 AM
Re: script for /etc/password
On solaris, look at 'passmgmt' man page for more information. I believe you may be interested in "-c" option. But some solaris gurus here can confirm it.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 07:15 AM
02-18-2004 07:15 AM
Re: script for /etc/password
Thanks a lot for the script I am close to getting this working.
Here is the script with a little changes.
Name of the Flat file is infile and looks like that
test: â comment comment
test2: â comment comment
test3⠦⠦
Name of the script file is idmod2:
!/bin/sh
`cat /export/home/infile`|while read LINE;do
name=`echo $LINE|awk -F":"'{print $1}'`
GECOS=`echo $LINE|awk -F":"'{print $2}'`
grep $name /etc/passwd >/dev/null 2>&1
if [ $? ];then
echo "Modifying $name"
usermod -c $name >/dev/null 2>&1 <<-!
$GECOS
none
none
none
!
fi
done
When I compile it, I get this error:
./idmod2 : test : â comment : not found
It looks that the script is working ok but there is a problem I canâ t but my hand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 07:20 AM
02-18-2004 07:20 AM
Re: script for /etc/password
test: "comment comment
test2: "comment comment
also the error is
./idmod2 : test : "comment : not found
I hope this text will show up ok
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 07:23 AM
02-18-2004 07:23 AM
Re: script for /etc/password
The script may not work completely due to following reasons.
1. If the /etc/passwd has users like user11, user100 and if your flat file has user1, then "grep $user /etc/passwd" is going to fail. So, you would want to put
grep -q "^${user}:" /etc/passwd
2. You will need to test $? against 0. You can eliminate > /dev/null 2>&1 with grep -q
grep -q "^${user}:" /etc/passwd
if [ $? = 0 ]
then
..
Look at my other script and instead of chfn, try your usermod command. A side note, 'usermod' will not work if the user is active atleast on HP systems. See if passmgmt works for you.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 07:29 AM
02-18-2004 07:29 AM
Re: script for /etc/password
The end quote " is missing. You don't need to have it
user1: some comments
user2: some comments
is enough.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 08:10 AM
02-18-2004 08:10 AM
Re: script for /etc/password
the syntax is
usermod -c "NEW COMMENT" username
as is
usermod -c "Joe Blow" jblow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 09:11 AM
02-18-2004 09:11 AM
Re: script for /etc/password
PASSWD=/etc/passwd
MYFILE=/export/home/infile
While read LINE
do
USER=$(echo $LINE|awk '{FS=":";print $1}')
GECOS=$(echo $LINE|awk '{FS=":";print $2}')
printf "%-20s""Doing for $USER"
grep -q "^${USER}:"$PASSWD
if [ $? = 0 ]
then
usermod -c $USER <
none
none
none
$GECOS
EOF
Print "- Done\n"
else
printf "-N/A\n"
fi
done < $MYFILE
This is your script I ran it against the infile and I got errors. I am not sure what is the problem with those 2 lines.
# ./idmod3
./idmod3[5]: While: not found
./idmod3[6]: syntax error at line 7 : `do' unexpected
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 09:13 AM
02-18-2004 09:13 AM
Re: script for /etc/password
# ./idmod2
./idmod2: test3:comment: not found
#
Abu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 09:13 AM
02-18-2004 09:13 AM
Re: script for /etc/password
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 09:13 AM
02-18-2004 09:13 AM
Re: script for /etc/password
-Sri
PS: I think I have enough points already. No more points please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2004 06:19 AM
02-19-2004 06:19 AM
Re: script for /etc/password
Here is the script
# cat idmod
#!/usr/bin/ksh
PASSWD=/etc/passwd
MYFILE=/export/home/infile
while read LINE
do
USER=$(echo $LINE|awk '{FS=":";print $1}')
GECOS=$(echo $LINE|awk '{FS=":";print $2}')
printf "%-20s""Modifying $USER"
/usr/bin/grep -nli "^${USER}:" $PASSWD
if [ $? = 0 ]
then
usermod -c $GECOS $USER <
none
none
none
$GECOS
EOF
echo "- Done\n"
else
echo "- Unable to Perform Your Request\n"
fi
done< $MYFILE
#