- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help with user delete script
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
06-17-2009 09:09 AM
06-17-2009 09:09 AM
Help with user delete script
I need to remove bunch of user that has UID "0" on my systems.
I have filter out all the users with the UIO "0" and have the list, also I have the server list for ssh.
What I am trying to fo is write simple loop something like this. but it's not working.
#!/usr/bin/sh
export RMVLST=$(cat usr.lst)
for X in $(cat srv.lst)
do
ssh ${X} grep ^$RMVLSTa /etc/passwd.test
done
I get the ERROR saying "grep can't open rmod.
Appreciate your help.
Thanks in advance for the help.
MJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2009 09:18 AM
06-17-2009 09:18 AM
Re: Help with user delete script
export RMVLST=$(< usr.lst)
for X in $(< srv.lst); do
>I get the ERROR saying "grep can't open rmod.
ssh ${X} grep ^$RMVLSTa /etc/passwd.test
This is basically tring to grep ALL of the tokens in usr.lst. grep will only take one token at a time, unless you use "-f file". Or another loop:
for user in $RMVLST; do
ssh ${X} grep ^$user /etc/passwd.test
(I'm not sure if that "a" is a typo?)
If you can send that file over to each system or have it NFS accessible, you could have "^name" on each line.
Or you can copy that passwd file back to your machine and process it there.
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2009 09:48 AM
06-17-2009 09:48 AM
Re: Help with user delete script
Thanks for the quick reply.
Yes, it was typo.
I did the way you are suggesting and get the following result.
ERROR = ssh: grep: no address associated with name
export RMVLST=$(< usr.list)
export SRVLST=$(< srv.lst)
for user in $RMVLST
do
ssh $SRVLST grep ^$user /etc/passwd.test
done
Thanks in advance - MJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2009 09:57 AM
06-17-2009 09:57 AM
Re: Help with user delete script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2009 10:09 AM
06-17-2009 10:09 AM
Re: Help with user delete script
>export RMVLST=$(< usr.list)
>export SRVLST=$(< srv.lst)
>for user in $RMVLST
>do
>ssh $SRVLST grep ^$user /etc/passwd.test
>done
Again, biting more than you can chew.
with this command
>ssh $SRVLST grep ^$user /etc/passwd.test
you are assuming you will loop thru the server list one server at a time, whereas ssh thinks all of those servers are one single server and crying fould not finding this server.
what you need to do
for s in $SRVLST
do
for u in $RMVLST
do
ssh ${s} "grep ${u} /etc/passwd.tst"
done #for variable u
done #for variable s
hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2009 10:15 AM
06-17-2009 10:15 AM
Re: Help with user delete script
The error "ssh: grep: no address associated with name"
...suggests that your variable ${X} is empty. you can see this if you did:
# ssh grep ^$RMVLST /etc/passwd
...where ${RMVLST} is defined.
For :
#!/usr/bin/sh
export RMVLST=$(< usr.list)
export SRVLST=$(< srv.lst)
for user in $RMVLST
do
ssh $SRVLST grep ^$user /etc/passwd.test
done
...as Dennis already noted, you need another loop to walk the list contained in ${SRVLST}.
#!/usr/bin/sh
RMVLST=$(< usr.list)
SRVLST=$(< srv.lst)
for user in ${RMVLST}
do
for host in ${SRVLST}
do
ssh -n ${host} grep ^${user} /etc/passwd.test
done
done
...Notice too that you do not need to 'export' your variables into your shell's environment.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2009 10:20 AM
06-17-2009 10:20 AM
Re: Help with user delete script
Ok, I am half way to my mission. A little help from you GURU's can put me in little success ship. LOL
This is what I came up with. I can run locally but I need to run on the remote server using ssh. I defiantly copy the working files over to each server.
And here is the loop, the issue is ssh part is not working. Please help.
#!/usr/sbin/sh
#export SRVLST=$(< srv.lst)
set -A users $(< user.list)
echo ${users[*]}
for user in ${users[*]}
do
#ssh $(SRVLST) grep ^${user##/*} /etc/passwd.test
grep ^${user##/*} /etc/passwd.test
done
Thanks in advance - MJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2009 10:21 AM
06-17-2009 10:21 AM
Re: Help with user delete script
Thanks,
MJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2009 01:43 PM
06-17-2009 01:43 PM
Re: Help with user delete script
I tried your options and now I can ssh into the server no prblem but my grep is not listing the user from the password file and not even giving me error.
Should I just copy the script to local node and then ssh to each server and just run it?
#!/usr/bin/sh
RMVLST=$(< usr.lst)
SRVLST=$(< srv.lst)
for user in ${RMVLST}
do
for host in ${SRVLST}
do
ssh ${host} "grep ^${user} /etc/passwd"
done
done
Thanks for everyones help.
MJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2009 03:28 PM
06-17-2009 03:28 PM
Re: Help with user delete script
> I tried your options and now I can ssh into the server no prblem but my grep is not listing the user from the password file and not even giving me error
Try isolating a test case at the command line:
# ssh -n somehost "grep ^root /etc/passwd"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2009 05:38 PM
06-17-2009 05:38 PM
Re: Help with user delete script
I tried from command line and it works.
ssh -n $SRVLST "grep ^root /etc/passwd"
ssh -n rp5470-prd "grep ^root /etc/passwd"
I think I need test this out by pushing the user.list file on to all my server and then run the loop.
Thanks for helping me out, appreciate that very much.
Any ideas are welcome.
JRF - Thanks again....
I will keep trying until I break it....LOL
Thanks,
MJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2009 12:21 AM
06-18-2009 12:21 AM
Re: Help with user delete script
Yes, unless you want to login multiple times.
Or you can copy the password file back to your machine, then process it.
>set -A users $(< user.list)
You really aren't buying much by creating an array.