- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting help...
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
09-25-2005 11:17 PM
09-25-2005 11:17 PM
I'm needing some help writing a script. For security reasons, I have to extract some info from /etc/passwd so the user acct manager can verify it against the application user accounts. I guess they got out of sync somehow. Anyway, I need a script to do the following:
1. Extract fields 1, 2, 4, and 5 from /etc/passwd.
2. Convert field 2 (password) into "Deactivated," "Activated," or "Blank."
3. Remove the system accounts from the final list.
Sounds easy enough, but I'm having a difficult time getting awk and cut to work in a desirable way.
Thanks!
Dwyane
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 11:24 PM
09-25-2005 11:24 PM
Re: Scripting help...
for i in $(logins -u|awk '{print 1}')
do
grep -i $i /etc/passwd| awk -F : '{print $1," ",$4,$5}'
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 11:27 PM
09-25-2005 11:27 PM
Re: Scripting help...
Convert field 2 (password) into "Deactivated," "Activated," or "Blank."
based on passwd -s
or ?
It will return only PS=passworded; LK=locked; and NP=no password.
Get back to get suitable script promptly.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 11:46 PM
09-25-2005 11:46 PM
Re: Scripting help...
# cp -p /etc/passwd /etc/passwd.bak
# grep -E "$(logins -u | awk '{ printf $1"|";} END { printf " " }')" /etc/passwd | awk -F":" '{ print $1," ",$4,$5 }'
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 11:57 PM
09-25-2005 11:57 PM
Solution#!/bin/ksh
# script.ksh
for user in `logins -u | cut -d" " -f1`
do
status=$(passwd -s $user | cut -d " " -f3)
case $status in
NP)
code="blank";
;;
LK)
code="Deactivated";
;;
PS)
code="Activated";
;;
esac
grep $user /etc/passwd | awk -F ":" -v var=$code '{ print $1,var,$4,$5 }'
done
exit 0
# END #
# chmod u+x script.ksh
# ./script.ksh
# Ouput #
smbnull Deactivated 101 DO NOT USE OR DELETE - needed by Samba
mysql Deactivated 102
iwww Deactivated 1
owww Deactivated 1
muthu blank 20
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2005 12:10 AM
09-26-2005 12:10 AM
Re: Scripting help...
to grep on /etc/passwd
say "user" is the variable
grep ^${user}":" /etc/passwd
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2005 12:22 AM
09-26-2005 12:22 AM
Re: Scripting help...
Try this:
# logins -uxo|perl -aF":" -ne 'printf("%10s %2s %3d %s\n",$F[0],$F[7],$F[3],$F[4]) if $F[1] > 100' -
The logins() utility shows PS for a valid password; LK for locked and NP for no password. These appear in the output above.
By limiting users to those with UID > 100, you effectively get (by default) a list without system users.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2005 02:38 AM
09-26-2005 02:38 AM
Re: Scripting help...
#!/bin/ksh
# set -x
> /tmp/passwd.bak
for user in `logins -uo | cut -d":" -f1`
do
status=$(passwd -s $user | cut -d " " -f3)
case $status in
NP)
code="BLANK";
;;
LK)
code="DEACT";
;;
PS)
code="ACT";
;;
esac
grep $user /etc/passwd | awk -F ":" -v var=$code '{ print $1," : ",var,"
: ",$5 }' >> /tmp/passwd.bak
done
# cat /tmp/passwd.bak
exit 0
Thanks to all for your help!
Dwyane
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2005 09:48 PM
09-26-2005 09:48 PM
Re: Scripting help...
I hope this will be useful for you, I have taken this from the ITRC Forms...But it was helpful for me, You can put some more for your active accounts in this script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2005 02:49 AM
09-27-2005 02:49 AM
Re: Scripting help...
Nice script! I made a copy for future use. This script requires a "trusted" system architecture. Mine aren't, currently...but will be in a few months.
Dwyane