1834403 Members
2637 Online
110067 Solutions
New Discussion

Re: KSH/SAM Question

 
Smucker
Regular Advisor

KSH/SAM Question

I have created a custom script for SAM in order to add users to multiple servers with a primary group and a supplementary group in the same script. I am having trouble adding the user to the supplementary group. This is what I have so far:

#!/bin/ksh
echo "\n\n\nThis script should be used to add new grp user and grp user accounts with a home directory"
echo "shell. If this is not what you want to do enter 'Cntl C' to exit. \n"
REPLY=N
case `echo $REPLY` in
y|Y|yes|Yes|YES ) echo "What is the user id ?? ====> \c"
read uname
echo "What is the new users name ?? =====> \c"
read username
echo "Office Location ?? =====> \c"
read officeloc
echo "What is the Password ?? =====> \c"
read passwd
echo "Office Phone ?? =====> \c"
read officephone ;;
n|N|no|No|NO ) echo "What is the user id ?? ====> \c"
read uname
echo "What is the new users name ?? =====> \c"
read username
echo "Office Location ?? =====> \c"
read officeloc
echo "Office Phone ?? =====> \c"
read officephone
echo "What is the Password ?? =====> \c"
read passwd
echo "Do you wish to add user to servername for group and group testing ?? =====> \c"
read servername_BOTH
if [[ $servername_BOTH = @(N|n|NO|No|no) ]]
then
echo "Do you wish to add the user to servername for group testing ?? =====> \c"
read servername_group
fi
if [[ $servername_group = @(N|n|NO|No|no) ]]
then
echo "Do you wish to add the user to servername for grp testing ?? =====> \c"
read servername_grp
fi ;;
esac
/usr/local/adduser/allsys "cat /etc/passwd | cut -d : -f 3" | sort -u -k 1n > /tmp/pass

UID=1500
while [ "$i" != "1" ]
do
grep $UID /tmp/pass > /dev/null
KEY=`echo $?`
if [ "$KEY" = "1" ]
then
if [[ $servername_BOTH = @(Y|y|YES|Yes|yes) ]]
then
echo "Adding $uname to servername for group testing"
remsh servername -n "/usr/sam/lbin/useradd.sam -u $UID -g group -s /usr/bin/sh -p '$(/usr/local/bin/Encrypt $passwd)' -d /home/$u -c '$username
,$officeloc,$officephone' $uname ; /usr/sam/lbin/upusrfiles -r $uname"
sleep 5 ;
echo "Adding $uname to servername for group testing"
remsh servername -n "/usr/sam/lbin/get_gr_mems |/usr/sam/lbin/grpusrs -m -l"$uname" group"
sleep 5
fi

i=1
else
UID=`echo $(( $UID+1 ))`
fi
done


I was thinking I might be able to use ("/usr/sam/lbin/grpusrs -m -l"$uname" group") and (/usr/sam/lbin/get_gr_mems group | /usr/bin/sort ???u) to get the current members of the group and concatenate them into the first process and add the new username. I am not sure how to redirect the group member???s output into the first command. Any suggestions on how to do this, or alternative methods would be greatly appreciated.
1 REPLY 1
John Dvorchak
Honored Contributor

Re: KSH/SAM Question

I would suggest using usermod, man usermod, to modify users with the remsh:

usermod -G group -g group username

Where G is alternate group and g is primary group.

from man usermod:

-g group Specifies the integer group ID or character
string name of an existing group. This
redefines the primary group membership of the
new login.

-G group Specifies the integer group ID or character
string name of an existing group. This
redefines the supplemental group memberships
of the new login. Duplicates within group
with the -g and -G options are ignored.
If it has wheels or a skirt, you can't afford it.