Computing.Net > Forums > Unix > extract user /etc/passwd & shadow

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

extract user /etc/passwd & shadow

Reply to Message Icon

Name: uribo
Date: April 9, 2003 at 07:32:32 Pacific
OS: Solaris
CPU/Ram: n.a.
Comment:

i am trying to select only username with uid > 500 in /etc/passwd and extract mindays, maxdays from /etc/shadow. can anyone help? thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: April 9, 2003 at 09:34:43 Pacific
Reply:

IFS=":" ; export IFS
cat /etc/passwd | while read username passwd_placeholder userid groupid capacity gecos home_dir shell; do
if [ $userid -gt 500 ] ; then
echo $username
shadow_line=`grep "^$username:" /etc/shadow`
echo "###$shadow_line###"
passwd=`echo $shadow_line | awk '{ print $2 }'`
lastchg=`echo $shadow_line | awk '{ print $3 }'`
min=`echo $shadow_line | awk '{ print $4 }'`
max=`echo $shadow_line | awk '{ print $5 }'`
warn=`echo $shadow_line | awk '{ print $6 }'`
inactive=`echo $shadow_line | awk '{ print $7 }'`
expire=`echo $shadow_line | awk '{ print $8 }'`
flag=`echo $shadow_line | awk '{ print $9 }'`
echo "Userid $passwd $lastchg $min $max $warn $inactive $expire $flag"
fi
done


0

Response Number 2
Name: uribo
Date: April 9, 2003 at 20:26:32 Pacific
Reply:

hi david,

im using bourne shell. what does the following lines mean?

passwd_placeholder userid groupid capacity gecos
home_dir shell; do

thanks!


0

Response Number 3
Name: uribo
Date: April 9, 2003 at 20:37:11 Pacific
Reply:

i got it, thanks!
p.s. pardon me, im very new to bourne shell. :)


0

Response Number 4
Name: uribo
Date: April 9, 2003 at 21:20:36 Pacific
Reply:

hi david,

can u explain why the following doesnt work:

#!/bin/sh

TEMPFILE1=/tmp/ehong.1.$$

IFS=":" ; export IFS
cat /cygdrive/h/etc/passwd | while read username passwd_placeholder userid groupid gecos home_dir shell; do
if [ $userid -gt 500 ] ; then
echo $username

shadow_line=`grep "^$username:" /cygdrive/h/etc/shadow`

`echo $shadow_line | awk -F: '{ print $1":"$3":"$4":"$5":"$6 }' /cygdrive/h/etc/shadow` > $TEMPFILE1
fi
done

i have been figuring out abt this for a week. i have problem extracting info from /etc/shadow with username input from /etc/passwd & output to a temp file for comparing data later on. help is appreciated! thanks!


0

Response Number 5
Name: David Perry
Date: April 10, 2003 at 03:18:25 Pacific
Reply:

You would surround a command with back ticks when you want to assign the output to a variable such as

var=`date +%Y%m%d`

You don't want them when you want the output written to a file as in your echo line being redirected to a tempfile above.


0

Related Posts

See More



Response Number 6
Name: uribo
Date: April 10, 2003 at 21:38:42 Pacific
Reply:

i just realise what i am doing might be wrong. my question is as follows:

###go through all HUMAN user password entries (you may assume that any user with a uid above 500 is a human user for the purposes of this assignment) and ensure that they have the following passwd and shadow setting set:
Minimum days to change password is 7
Maximum life of a password is 30 days, and the users will be asked to change their password for 5 days up to the end of the time their password is valid.
Ensure that the "last changed" setting for each user occurs in the past. Report any that do not match this (include the date set in the shadow file in the report)###

what i am doing above is extract data to a temp file. how do i update the correct settings later on?


0

Response Number 7
Name: David Perry
Date: April 11, 2003 at 05:04:02 Pacific
Reply:

Does usermod or vipw help?


0

Response Number 8
Name: uribo
Date: April 11, 2003 at 05:43:06 Pacific
Reply:

no, im running this script as root. i have to ensure all affected users (i.e.>500) have the correct settings in the shadow file. any suggestion?


0

Response Number 9
Name: David Perry
Date: April 11, 2003 at 10:42:33 Pacific
Reply:

not an easy answer but you could alter the fields with sed to create a new file with the same permissions then replace the working /etc/shadow with the new one

cp -p /etc/shadow /etc/shadow.working
sed -e 's/^$username:.*:/$username:somevalue:/ /etc/shadow > /etc/shadow.working && mv /etc/shadow.working /etc/shadow


0

Response Number 10
Name: uribo
Date: April 14, 2003 at 22:12:29 Pacific
Reply:

thanks for all the help, david!


0

Response Number 11
Name: hoichoi
Date: April 23, 2003 at 03:04:18 Pacific
Reply:

I've got one query of the problem that is mentioned by uribo that is ...

"Ensure that the "last changed" setting for each user occurs in the past. Report any that do not match this (include the date set in the shadow file in the report."

How it can be done by bourne shell ?


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: extract user /etc/passwd & shadow

Help! etc/passwd deleted! Telnet Not All www.computing.net/answers/unix/help-etcpasswd-deleted-telnet-not-all/2174.html

Removing old users from /etc/passwd www.computing.net/answers/unix/removing-old-users-from-etcpasswd/7674.html

information in the /etc/passwd www.computing.net/answers/unix/information-in-the-etcpasswd/6255.html