To get total number of users and their groups in remote UNIX machine

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To get total number of users and their groups in remote UNIX machine
# 1  
Old 02-26-2014
To get total number of users and their groups in remote UNIX machine

Hi All

I am trying to do ssh to different server and on the remote server for each user trying to get groups of that user but i am not getting the required

ssh username@ip_address  "for i in $( cat /etc/passwd| cut -d: -f1);do groups $i done;exit" >>abc.txt

only names are getting shown but not there groupnames..

Please help me in this.

Last edited by Scrutinizer; 02-26-2014 at 03:52 PM.. Reason: code tags
# 2  
Old 02-26-2014
Try using single quotes rather than double quotes..
# 3  
Old 02-26-2014
I have tried like this

ssh username@ipaddress 'for i in $( cat /etc/passwd| cut -d: -f1);do groups $i done' >>abc.txt

it gave me the below error

bash: -c: line 1: syntax error: unexpected end of file

Moderator's Comments:
Mod Comment Use code tags, please.

Last edited by Corona688; 02-26-2014 at 04:06 PM..
# 4  
Old 02-26-2014
I think you're missing a ; before done.
# 5  
Old 02-26-2014
Thanks a lot it worked.

But now i want to fetch the last few lines of /etc/sudoers file in this at the end for the same remote server.

How can i get that in the same server. i am trying to use from the below command
ssh user@ip 'for i in $(cat /etc/passwd|cut -d: -f1); do groups $i; done;tail -20 /etc/sudoers' >> abc.txt

ALso one more problem is that /etc/sudoers can only be viewed by root for which i only have the sudo access. Any way i can achieve that.

Last edited by vbe; 02-26-2014 at 04:52 PM..
# 6  
Old 02-27-2014
sudo tail -20 /etc/sudoers ?
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to write a UNIX script to send a mail to the respective individual users about their groups?

Hi Team, I got a requirement to send a mail to the individual users of a unix server about their respective groups. can some one help me to provide the script as I am unable to write that. I tried with below lines but I come out with errors. cat /etc/passwd | awk -F':' '{ print $1}' |... (6 Replies)
Discussion started by: harshabag
6 Replies

2. UNIX for Dummies Questions & Answers

How to run UNIX commands on remote machine from windows?

Hi All, I am working in support and we are planning to automate a system to reduce the direct manual intervention to core system. Please find the below details. 1. we have a web application that runs on Windows Platform. 2. From web application, we need to connect to remote Unix machine.... (6 Replies)
Discussion started by: Balaji K
6 Replies

3. Solaris

unable to sftp to a remote server from Unix machine

Hi, I get the below when i try to sftp to a remote server $ export SOCKS5C_CONFIG=~/.ssh/socks5c.conf $ sftp -v -s /usr/lib/sftp-server -oPort=2222 -oIdentityFile=~/.ssh/wm_privat> Connecting to Sun_SSH_1.1.3, SSH protocols 1.5/2.0, OpenSSL 0x0090704f debug1:... (1 Reply)
Discussion started by: Bigbee
1 Replies

4. Shell Programming and Scripting

Total number of users logged in a server from uptime

how to find out total number of users logged in a server from uptime . i mean to say i need the total output of unix command . who gives the out put at a particular time . I need at all time from which machine who has connected , (3 Replies)
Discussion started by: amiya.te@gmail
3 Replies

5. Programming

Ping remote UNIX machine from a java application

Hi Friends, Can some one please guide me on how to make a script run on a remote UNIX machine from a java application. Or may if you can just tell me how do u ping to the remote UNIX machine using java code. Been looking for the solution since 5-6 hrs, didn't got any where near :( Thanks. (1 Reply)
Discussion started by: Sanjay MD
1 Replies

6. Solaris

Defaults number of users and Groups

Hi All, I would like know how many of default number of users and groups are there in solaris-10... Regards Tirupathi Raju (2 Replies)
Discussion started by: tirupathiraju_t
2 Replies

7. UNIX for Dummies Questions & Answers

Finding out all users and their UNIX groups??

Is there a way to find out all users and the UNIX groups they belong to?? :) (3 Replies)
Discussion started by: Hangman2
3 Replies

8. UNIX for Dummies Questions & Answers

Copy file from Remote Unix box to windows machine

Hi I need to copy a file from the remote unix server to windows machine. I read lot of thrad but didn't worked out. Requesting all to please help. (2 Replies)
Discussion started by: sameerspice
2 Replies

9. UNIX Desktop Questions & Answers

Creating New Users in UNIX Machine !!!

Hi How to create users in the UNIX machine .... I am the ROOT and i want to create users with normal privileges . a) Please give the sequence of commands which i need to use. b) How to set their userid and passwords (3 Replies)
Discussion started by: skyineyes
3 Replies

10. UNIX for Advanced & Expert Users

Identify a remote machine as windows or unix

Hi, I have a IP address of the target machine.Is there is any way to find out whether it is a unix box or windows box without logging into it?. Regs Anand (5 Replies)
Discussion started by: u449064
5 Replies
Login or Register to Ask a Question