Operating System - HP-UX
1753506 Members
5294 Online
108794 Solutions
New Discussion юеВ

Script to find and delete a user account from multiple HP-UX servers

 
SOLVED
Go to solution
gnana prakasam
Advisor

Script to find and delete a user account from multiple HP-UX servers

Hi all,

Some times i am in need of logging in multiple servers and to find out for some useraccounts to delete it.Is there any script available to do it with out logging in all the servers.SUDO access with out asking password is permitted in my useraccount.

User id & password is same for all systems.

Give me some solutions

 

 

Prakash

7 REPLIES 7
Dennis Handly
Acclaimed Contributor

Re: Script to find and delete a user account from multiple HP-UX servers

If you have NIS or LDAP, you could manage your users centrally.

 

Otherwise you could use ssh to run scripts on each machine.

Do you shared /home or other directories on all machines?

gnana prakasam
Advisor

Re: Script to find and delete a user account from multiple HP-UX servers

HI dennis,

We don't have NIS or LDAP .No shared directories on all machines.

Is there any other way ?

James R. Ferguson
Acclaimed Contributor

Re: Script to find and delete a user account from multiple HP-UX servers

Hi:

 

You could setup SSH public keys and once done, use 'ssh' to remotely manage your accounts.

 

Regards!

 

...JRF...

Doug O'Leary
Honored Contributor

Re: Script to find and delete a user account from multiple HP-UX servers

Hey;

 

>>Some times i am in need of logging in multiple servers and to find out for some useraccounts to delete it.Is there any script available to do it with out logging in all the servers.

 

Without a centralized user management system such as LDAP or NIS, you obvioulsy *have* to log into each machine in order to manage the accounts because that's where they're defined.  

 

There are no predefined scripts as far as I know.  However, the psuedo code algorithm for what you're looking for is relatively easy:

 

for host in ${list-o-hosts}

do

   useradd/del ${user} on ${host}

done

 

Now, the trick is to figure out a good way to access the hosts.  Someone already mentioned ssh using public key authentication (pka).  That is hands down the best way available without spending money.  You can also write perl/expect scripts to automate password authentication using either telnet or ssh.  

 

I advocate using ssh/pka to directly access root and other sensitive accounts as it's more secure for a variety of reasons.  A white paper outlining those reasons is available but is off topic.  Search these forums for it or send me an email and I'll get the url to you.

 

So, assuming ssh/pka access to root:

 

user=$1

for h in $(cat hosts)

do

echo ${h}

ssh ${h} "grep ^${user}: /etc/passwd 2>/dev/null" | \

          grep -q ${user} && ssh -n -x -l root ${h} userdel -r ${user}

done

 

There are plenty of other things you could do - find all the user's files, back up home directory, send emails, etc, etc; however, that loop will get you the gist of what you were looking for.

 

Doug


------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
gnana prakasam
Advisor

Re: Script to find and delete a user account from multiple HP-UX servers

Will use and confirm as soon

 

gnana prakasam
Advisor

Re: Script to find and delete a user account from multiple HP-UX servers

If i want to delete multiple users  from multiple servers on a regular basis like monthly.

what would be the solution?

can you a provide a script?

Dennis Handly
Acclaimed Contributor
Solution

Re: Script to find and delete a user account from multiple HP-UX servers

>If I want to delete multiple users  from multiple servers on a regular basis like monthly.

 

Doug provided a script to delete one user.  You just put that in a loop to handle multiple users on the command line:

for user in $*; do

   for h in $(< hosts); do

      echo ${h}

      ssh ${h} "grep ^${user}: /etc/passwd 2>/dev/null" | \

          grep -q ${user} && ssh -n -x -l root ${h} userdel -r ${user}

   done

done