?
Solved

SunOS Bash Shell for User groups

Posted on 2010-09-20
3
Medium Priority
?
808 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 79

Accepted Solution

by:
arnold earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

770 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