• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

script to change group from a file having list of users

June 17, 2011 by Sharad Chhetri Leave a Comment

In this post we are sharing the script to change group from a file having list of users. You can do the changes in script as per your requirement.
The script is also using the /etc/group file to validate group names which could be existing in user supplied group file.

Given below is the sample script.

#!/bin/bash

##########################################################
#This script is made to change the group id ##
# Author: Sharad Kumar Chhetri ##
# Blog: https://sharadchhetri.com
# Date of Creation: 17-Jun-2011
# Version: 1.1
##########################################################
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

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to list users above or below particular user id
  2. Set group password,its use and check which group after newgrp command in linux
  3. group ownership reference to file/dir from other file/dir in linux
  4. NOTICE: nagios.cmd file not found. Please specify the location of this file in your /etc/vshell.conf file
  5. How to list all installed python modules
  6. list files and directories by 4 commands in linux
  7. linux command to list the files from rpm package without extracting
  8. how to mount NAS storage in owncloud to keep all users data
  9. Secondary Logging : Save All Users History Command Output As Log
  10. Nagios monitoring on AWS Autoscaling group instances

Filed Under: Linux Tagged With: bash script

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

30 useful Linux terminal keyboard shortcuts

The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form

Convert new line to space by using sed command

How to convert rpm file into deb file

Run the script using nohup without hitting enter key two times

fatal error: error writing to /tmp/ccwAjc9Z.s: No space left on device

How to configure ethernet in CentOS 6 after installing in Virtual Box

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy