Solved

SunOS Bash Shell for User groups

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

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

Independent Software Vendors: 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

Suggested Solutions

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
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…

733 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