- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting question
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
01-19-2005 09:22 PM
01-19-2005 09:22 PM
Scripting question
I need to clean up a passwd file ( 150 dormant accounts). I have the list of user ids to be removed. Does anyone have a sed/perl script written for this purpose? It's not a secure OS yet, so I can edit the /etc/passwd file directly.
Thanks
Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2005 09:28 PM
01-19-2005 09:28 PM
Re: Scripting question
how about:
#!/usr/bin/sh
while read record
do
userdel -r $record
done < list_of_users.dat
for help look at man userdel
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2005 09:34 PM
01-19-2005 09:34 PM
Re: Scripting question
DEL
e.g.:
DEL hpdb
DEL kmo
copy del to a directory
copy the password file to a directory
create the following file called cleanit.awk:
BEGIN {FS=":";}
/^DEL/{FS=" ";
countit++;
todel[countit]=$2;
FS=":";next}
{daflag=0;
for (idx1 in todel)
if (todel[idx1]==$1) {daflag=1;}
if (!daflag) {print $0;}
}
run the following commands:
cat del passwd > useme
awk -f cleanit.awk < useme > newfile
diff passwd newfile
Might not be the prettiest thing around, but it will work.
Best regards,
Oz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2005 09:35 PM
01-19-2005 09:35 PM
Re: Scripting question
First, make a safe backup copy of /etc/passwd before you do anything else!
Who needs sed or perl? Try something like this:
cp -p /etc/passwd passwd.safe
cp /etc/passwd passwd.tmp
for user in `cat deadusers.txt`
do
grep -v "^${user}:" passwd.tmp > passwd.tmp2
mv passwd.tmp2 passwd.tmp
done
cp passwd.tmp /etc/passwd
hope that helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2005 09:40 PM
01-19-2005 09:40 PM
Re: Scripting question
if you put all the IDs to delete to a file then you can use grep to remove them.
Just do something like:
grep -v -f yourfilewithids /etc/passwd > /tmp/newpasswd
Of course doublecheck the result befor you replace the original /etc/passwd
Hope this helps
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2005 09:42 PM
01-19-2005 09:42 PM
Re: Scripting question
o you have only uid not user names use it:
#!/bin/sh
if [ -f $1 ]
then
INF=$1
else
exit
fi
for ID in `cat ${INF}`
do
UNAME=`cat /etc/passwd | grep ":${ID}:" | awk -F':' '{print $1}'`
CMD="userdel -r ${UNAME}"
echo ${CMD}
${CMD}
done
# $1 - file name of uid-s
ex:
106
107
108
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2005 10:02 PM
01-19-2005 10:02 PM
Re: Scripting question
make a file of users to be deleted
for i in 'cat file'
do
userdel -r $i
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2005 10:06 PM
01-19-2005 10:06 PM
Re: Scripting question
one more
#cat /etc/passwd |awk -F: '{print $1}' > file
for user in 'cat file'
do
echo " Do you want $user to be deleted"
read x
if ($x==y)
userdel -r $user
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2005 09:56 AM
01-20-2005 09:56 AM
Re: Scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2005 09:12 PM
01-20-2005 09:12 PM
Re: Scripting question
for user in `cat deadusers.txt`
do
passwd -l $user
done
They can then be re-activated later, if necessary, and all of their files will still be there if they're ever needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2005 09:58 PM
01-20-2005 09:58 PM
Re: Scripting question
also attached a script to identify dormant users i.e. users who have not logged on in the 30 days. May be useful in future
Regards