Guest_imported
New member
- Jan 1, 1970
- 0
This script fetches users and their groups. I was trying to make a function or something where I call groups $USER_ID instead of printing it out each time.
Here is how it is now:
[tt]
cat myFile | while read LINE
do
USER_ID=`echo $LINE | awk -F: '{print $1}'`
REAL_NAME=`echo $LINE | awk -F: '{print $2}'`
i=`groups $USER_ID | awk '{print NF}'`
echo "-----------------------------------------"
if (( $i == 1 ))
then
echo "$REAL_NAME is a member of $i group:"
groups $USER_ID
else
echo "$REAL_NAME is a member of $i groups:"
groups $USER_ID
fi
done[/tt]
Here is my attempt at putting the groups $USER_ID in a variable:
[tt]
cat myFile | while read LINE
do
USER_ID=`echo $LINE | awk -F: '{print $1}'`
var=`groups $USER_ID`
REAL_NAME=`echo $LINE | awk -F: '{print $2}'`
i=`groups $USER_ID | awk '{print NF}'`
echo "-----------------------------------------"
if (( $i == 1 ))
then
echo "$REAL_NAME is a member of $i group:"
$var
else
echo "$REAL_NAME is a member of $i groups:"
$var
fi
done[/tt]
I keep getting an error message with the $var variable. Please advise the most proficient way of doing this?
Here is how it is now:
[tt]
cat myFile | while read LINE
do
USER_ID=`echo $LINE | awk -F: '{print $1}'`
REAL_NAME=`echo $LINE | awk -F: '{print $2}'`
i=`groups $USER_ID | awk '{print NF}'`
echo "-----------------------------------------"
if (( $i == 1 ))
then
echo "$REAL_NAME is a member of $i group:"
groups $USER_ID
else
echo "$REAL_NAME is a member of $i groups:"
groups $USER_ID
fi
done[/tt]
Here is my attempt at putting the groups $USER_ID in a variable:
[tt]
cat myFile | while read LINE
do
USER_ID=`echo $LINE | awk -F: '{print $1}'`
var=`groups $USER_ID`
REAL_NAME=`echo $LINE | awk -F: '{print $2}'`
i=`groups $USER_ID | awk '{print NF}'`
echo "-----------------------------------------"
if (( $i == 1 ))
then
echo "$REAL_NAME is a member of $i group:"
$var
else
echo "$REAL_NAME is a member of $i groups:"
$var
fi
done[/tt]
I keep getting an error message with the $var variable. Please advise the most proficient way of doing this?