1833861 Members
2262 Online
110063 Solutions
New Discussion

User remove script

 
SOLVED
Go to solution
SagarOne
New Member

User remove script

Hello friends,

I have created one user remove script which is run on one stepping stone linux server. I have my athourisation key on all the remote servers. but when i run this script it hanged. could you help me. here is the script which i have created:
#more userdel
for i in host
do
ssh $i /appl/tsu/bin/sudo userdel -r $1
done
5 REPLIES 5
Kenan Erdey
Honored Contributor

Re: User remove script

Hi,

where do you get host variable's value from ? also if you first ssh to servers it'll ask for authenticity. you can also put #!/usr/bin/bash -x for debugging to reliase where it hangs.

Kenan.
Computers have lots of memory but no imagination
Ivan Krastev
Honored Contributor

Re: User remove script

Also set PATH in your script or use full path names for userdel.

regards,
ivan
Suraj K Sankari
Honored Contributor

Re: User remove script

Hi,

For this type of multiple server script the best way is to put your script into every server /home directory or other location then run your script from your master server.

for i in `cat serverlist.txt`
do
ssh $i /home/scriptname.sh
done

Suraj.
Doug O'Leary
Honored Contributor
Solution

Re: User remove script

Hey;

First, it's generally a bad idea to call a script the same name as a OS binary. The reason is if your path is messed up, it will find the script before the binary. If you want to call it something close, use a capital letter or call it userrm - something along those lines.

There are a couple of possibilities of what's causing the issue.

1. Issue with the user: $1. Set the $1 variable to *something* in your script:

User=$1

I try to avoid using the positional variables, particularly in loops as they're pretty easy to stomp.

2. sudo authentication. Unless you're using NOPASSWORD option (always a bad idea), the sudo will ask for your password every 5 minutes. You can initially populate the cache by looping through the hosts and doing something like sudo ls -ld /tmp

3. If the user doesn't exist on the remote system, it may cause issues with your script. I would think it'd just display an error message..

Those are the things I'd check...

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
SagarOne
New Member

Re: User remove script

Thanks to all
but i have run the script in debug mode, o/p is here:

# ksh -x ./userdel user
+ ssh server /appl/tsu/bin/sudo user


after that it hanged,user exist on the server, also when i run the following cmd, it run sucessfully:

ssh server /appl/tsu/bin/sudo userdel -r user

dont know why its not running when putting on script & passing value.