Operating System - HP-UX
1830934 Members
2453 Online
110017 Solutions
New Discussion

Re: script for deleting users

 
Raymond Ford
Advisor

script for deleting users

The requirement is for a daily method to gather the /etc/passwd files from 10 remote systems to store on server "A". When a user departs the organization a script is then to be run to determine which systems require deletion of the user's account and group memberships. I presume the files are to be stored on server A to enable the updated passwd file(s) to be modified and ftp'd to affected systems. I've been clued in to use a series of commands in a .netrc file to gather the passwd files. When it comes to deleting lines from appropriate passwd files stored on server A I am way behind the power curve. As I delve through the usual shell textbooks searching for the light, I again spin my wheels at scripting something that seems simple. I also wonder about modifications to the etc/group and other files, but those issues may arise on another day. Thank-you for any direction you may provide. Starting anew after 44 years is a bear.
I'm an apprentice among journeymen who spend a lot of time on the virtual road.
5 REPLIES 5
Roger Baptiste
Honored Contributor

Re: script for deleting users

hi,

if you know the userids of the users to be removed , you can do it by simply using the
"userdel" command
userdel loginid
userdel -r loginid (if you want to remove the users home directory too).

You can run this through remsh :
A simple format would be:
for i in `cat hostnames`
do
remsh userdel -r loginid
if [ $? -eq 0 ]
then
echo "user $loginid removed from $host" >>logfile
else
echo " user $loginid not removed from $host. User may not be present on the system" >>faillog
fi
done


HTh
raj
Take it easy.
Tom Geudens
Honored Contributor

Re: script for deleting users

Hi,
The problem is not in collecting the passwd files (as you mentioned, with ftp) or deleting the users (I would generate "userdel" scripts - and not forget to remove/move the files/directories these users had - ftp those back to the appropriate systems and execute them there, rather than start messing with the passwd files).
However, the problem is in scheduling all those things to happen sequentially spanning several different servers. For that I would use Control-M, but that's an "external" software ... I don't know if you have a "Cross Server Job Scheduler" or have to rely on good old crontab. In the latter case it's going to be tricky.

Hope this gets you started,
Tom Geudens
A life ? Cool ! Where can I download one of those from ?
Ceesjan van Hattum
Esteemed Contributor

Re: script for deleting users

My answer will not help you on the short term, but for the long(er) term it might be an idea to start to think about NIS.
Besides /etc/passwd and /etc/group modifications, did you also think about what to do with the /home directory of the user to be deleted..? Putting homedirecoties centralized using automounter (autofs) is an other thing to think about.

Regards,
Ceesjan
Clemens van Everdingen
Honored Contributor

Re: script for deleting users

Hi,

As already stated by Ceesjan, start investigating using NIS+ and a NFS mounted filesystem for the users home directories.

That would be the easiest way to manage user adding and deleting.

Regards,
Clemens
The computer is a great invention, there are as many mistakes as ever, but they are nobody's fault !
Raymond Ford
Advisor

Re: script for deleting users

Thank-you all for your suggestions. This assignment never made much sense to me. Why just the passwd files? We are neither talking about a large number of servers, nor about user accounts that need to be deleted with any frequency. RajMan, I neglected to mention that remsh is not to be used for "security" reasons. Makes me wonder why I have root privileges. I'll get to work with .netrc and look into NIS. You all deserve 10 points in my book, but I try to stick by the conventions ;-)
I'm an apprentice among journeymen who spend a lot of time on the virtual road.