Solved

SunOS Bash Shell for User groups

Posted on 2010-09-20
3
798 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now