Solved

SunOS Bash Shell for User groups

Posted on 2010-09-20
3
804 Views
Last Modified: 2013-12-27
Ok I need some help on this one, as I am about to beat a whole in my head from staring at my screen.

Basically I am trying to take a list of usernames in a text file and run the 'groups' command against each one in the file.  Normally my script would look like this:

# for users in $(cat users.txt); do groups $users; done > groups.txt

but for some STUPID reason the sun box I am running this on does not like the "$(cat users.txt)" entry
So I have tried it every way i can think of:

# for users in 'cat users.txt'; do groups $users; done > groups.txt
# for users in (cat users.txt); do groups $users; done > groups.txt
# for users in "cat users.txt"; do groups $users; done > groups.txt
# for users in cat users.txt; do groups $users; done > groups.txt

I typically get the message below:
groups: cat : No such user
groups: users.txt : No such user

Can someone help with this before I smash this box...


 
0
Comment
Question by:nakoz69
3 Comments
 
LVL 77

Accepted Solution

by:
arnold earned 500 total points
ID: 33722682
No point in trying to `cat users.txt` is the execute bits.
try one below

cat users.txt | while read a; do
groups $a >> groups.txt
done

or
cat users.txt | (while read a; do
groups $a
done) > groups.txt
0
 
LVL 48

Expert Comment

by:Tintin
ID: 33722981
The reason

 $(cat users.txt)

doesn't work is almost certainly because the root shell is not bash, it will be sh.  Bourne shell doesn't support the $(cmd) syntax, so you have to use backticks instead, eg:

for users in `cat users.txt`; do groups $users; done > groups.txt

Note, that that's a ` and not a '

0
 
LVL 1

Author Comment

by:nakoz69
ID: 33726119
Thank you sir! It worked great!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question