LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-11-2005, 06:07 PM   #1
ziox
Member
 
Registered: Apr 2004
Distribution: RedHat, Fedora, Suse, Debian, Gentoo, Mandrake
Posts: 132

Rep: Reputation: 15
piping variables from stdin


Hello ...

How to assign variables to an output of a command ??..

specially something like that...

groups $USER | cut -f4,5,6 -d \ ; then i want to assign the output

with something like "read" or any so i can use those variables somewhere

else
 
Old 02-11-2005, 09:12 PM   #2
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
OUTPUT=`groups $USER | cut -f4,5,6 -d \ ;`

Put the command in backticks
 
Old 02-12-2005, 03:38 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
OUTPUT=$(groups $USER | cut -f4,5,6 -d \

Or in side $(..)
(bash only)
 
Old 02-12-2005, 06:43 PM   #4
ziox
Member
 
Registered: Apr 2004
Distribution: RedHat, Fedora, Suse, Debian, Gentoo, Mandrake
Posts: 132

Original Poster
Rep: Reputation: 15
thanks
but what i wanted to do is take the output
of this command
groups $uzr | cut -f4,5,6 -d \ ;
then assign it with $x , $z
$1 = a group name i added in the script

usermod -G $1,$x,$z $uzr

The Script Is That...
____________________
#!bin/bash
#creating a group then assigning all users to it ....
groupadd $1
cd /home && echo "Making $1 Directory"
mkdir -m 3770 $1 ;
chgrp $1 $1
cd /home/$1
for uzr in `grep /home /etc/passwd | cut -f 1 -d :`
do
groups $uzr | cut -f4,5,6 -d \ ;

"(the problem here)..assign the output (the fields i catted)from the previous line
to $x,$o,$j and so forth....to prevent deleting users from old-groups when i creat
a new one...

usermod -G $1,$x,$o,$j $uzr
mkdir -p -m 3770 $uzr"_dir"
done
echo "Users Has Been Added To $1 Group"

_______________________________________________

Last edited by ziox; 02-13-2005 at 07:20 AM.
 
Old 02-13-2005, 07:39 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
If I were you, I would avoid put all users from /etc/passwd in a new created group,
I woul make a limited users list instead...

For the loop I would do :
Code:
# I follow your wish, all users from passwd
userslist=`cat /etc/passwd  | cut -d: -f1`

for user in $userslist; do
    # all $user groups
    groups=`id $user -Gn`
    # all groups, coma separated
    groups=`echo $groups | sed -e 's/ /,/g'`
    # remove echo if you're satisfied
    echo "usermod -G $1,$groups $user"
    echo "mkdir -p -m 3770 $user_dir"
done

Last edited by keefaz; 02-13-2005 at 07:42 AM.
 
Old 02-13-2005, 08:29 AM   #6
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
Quote:
Originally posted by keefaz
If I were you, I would avoid put all users from /etc/passwd in a new created group,
I woul make a limited users list instead...
Why? There are plenty of situations where this would be not only perfectly acceptable but the only possible means to an end.
 
Old 02-13-2005, 06:56 PM   #7
ziox
Member
 
Registered: Apr 2004
Distribution: RedHat, Fedora, Suse, Debian, Gentoo, Mandrake
Posts: 132

Original Poster
Rep: Reputation: 15
Thanks
it work now fine
_______________________________

#!bin/bash
#creating a group then assigning all users to it ....
groupadd $1
cd /home && echo "Makeing $1 Directory"
mkdir -m 3770 $1 ;
chgrp $1 $1
cd /home/$1
uzrlist=`grep /home /etc/passwd | cut -f 1 -d :`
for uzr in $uzrlist
do
grps=`id $uzr -Gn | cut -f2,3,4,5 -d \ | sed -e 's/ /,/g'`
usermod -G $1,$grps $uzr
mkdir -p -m 3770 $uzr"_dir"
done
echo -e "$uzrlist \n\tHas Been Added To $1 Group"

Last edited by ziox; 02-13-2005 at 07:19 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
stdin and NUL. How ? Mike Davies Linux - Software 5 10-28-2004 07:06 AM
unbuffered stdin mvt Programming 7 05-17-2004 09:40 PM
Shel scripting: variables pointing to variables and case Dark_Helmet Programming 5 06-08-2003 11:07 AM
Telnet user redirectng/piping stdin/out? MikHud Linux - General 2 02-11-2002 04:18 AM
Telnet user redirectng/piping stdin/out? MikHud Linux - Networking 0 01-30-2002 10:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration