Wednesday, September 3, 2014

[Quick Tips] : script to change group from a file having list of users

script to change group from a file having list of users

script to change group from a file having list of users
This is a example script.
#!/bin/bash
##########################################################
#This script is made to change the group id ##
#Author: xyz ##
##########################################################
echo “Note: User list file and the script must be in same dir and should be run from same dir”
echo “”
echo “Currently You are in => pwd
echo “list of files in this dir => ls -l
echo “Give the name of file which has Users Name”
read userfile
echo “You have selected the file called $userfile”
echo “Give the Group Name in which user will be added”
read grpname
grpcheck=grep $grpname /etc/group|cut -d: -f1
echo $grpcheck
if [ -f $userfile ];then
echo “$userfile file is found”
else
echo “$userfile file not found”
echo “U r going to exit in 2seconds”
sleep 2
exit
fi
if [ $grpname == $grpcheck ];then
echo “$grpname group is found”
else
echo “$grpname group is not found”
echo “U r going to exit in 2seconds”
sleep 2
exit
fi
echo “Do u want to continue (Y/N)”
read xyz
case $xyz in
Y|y) for i in cat $userfile;do usermod -g $grpname $i;done;;
[Yy][Ee][Ss]) for i in cat $userfile;do usermod -g $grpname $i;done;;
N|n) exit;;
[Nn][Oo]) exit;;
*) exit;;
esac
echo “Status After Running the Script– Check UserID and GroupID”
for i in cat $userfile
do id $i
done

No comments: