Solved

SunOS Bash Shell for User groups

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

Accepted Solution

by:
arnold earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you sir! It worked great!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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 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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

743 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

17 Experts available now in Live!

Get 1:1 Help Now