NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#!/bin/bash
#!/bin/bash
clear #clearing the screen
green=$( tput setaf 2 ) #Assigning tput green color attribute to green variable
red=$( tput setaf 1 ) #Assigning tput red color attribute to red variable
mag=$( tput setaf 5 ) #Assigning tput magenta color attirbute to mag variable
bold=$( tput bold) #Assigning bold attribute tp bold variable
rev=$( tput rev ) #Assigning reverse mode attribute to rev variable
defColor=$( tput sgr0 ) #Assigning tput default color attribute to the defColor variable

function user_password
{
if [ "$1" != '' ];
then
username=$1;

else
read -p "Enter the username to change password: " username
fi
passwd "$username"
}

function add_user
{
read -p "Enter Username: " username
useradd "$username"
user_password "$username"
uid=`id -u "$username"`
echo "${green}User Added Successfully with user ID :${rev}${bold}${uid}${defColor}"
}

function del_user
{
read -p "Enter Username: " username
userdel "$username"
echo "${green}User ${bold}${username}${defColor}${green} has been deleted successfully${defColor}"
}

function username_change
{
read -p "Enter current username to change: " curusr
read -p "Enter new username: " newusr
usermod -l "newusr" "curusr"
echo "${green}Username changed from ${bold}${curusr}${red}-->${green}${newusr}${defColor}"
}

function uid_change
{
read -p "Enter username whose UID you want to change: " curusr
curuid=`id "$curusr" | grep -oP 'gid=KS+'`
read -p "Enter new UID: " newuid
usermod -u "$newuid" "$curusr"
echo "${green}UserID changed from ${bold}${curuid}${red}-->${green}${newuid}${defColor}"
}

function get_gid
{
groupname=$1
#searching for groupname in /etc/group and then extracting the GID using sed
gid=$( sed -nr "s/^$groupname:x:([0-9]+):.*/1/p" /etc/group ) #stream editing with sed
#sed searches for the line where there is the given groupname and extracts the GID
echo "$gid"
}
function grpname_change
{
read -p "Enter current Group name to change: " curgrp
read -p "Enter new Group name: " newgrp
groupmod --new-name "$newgrp" "$curgrp"
echo "${green}Group name changed from ${bold}${curgrp}${red}-->${green}${newgrp}${defColor}"
}

function grpid_change
{
read -p "Enter Group name whose ID you want to change: " curgrp
curgid=`get_gid "$curgrp"`
read -p "Enter new Group ID: " newgid
groupmod -g "$newgid" "$curgrp"
echo "${green}Group ID changed from ${bold}${curgid}${red}-->${green}${newgid}${defColor}"
}

function del_grp
{
read -p "Enter Group name: " grpname
groupdel "$grpname"
echo "${green}Group ${bold}${grpname}${defColor}${green} has been deleted successfully${defColor}"
}

function edit_user
{
clear
echo "1. Change Username "
echo "2. ${rev}Change Password ${defColor}"
echo "3. Change UID"
echo "4. ${rev}Back to main menu${defColor}"
read -p "Enter any option from [1-3]: " opt
if [[ "$opt" =~ ^[1-4]{1}$ ]];
then
case "$opt" in
1) username_change;;
2) user_password;;
3) uid_change;;
4);;

esac
echo
echo
else
echo "${red}Invalid Input${defcolor}"
fi
}

function add_grp
{
read -p "Enter Groupname: " grpname
groupadd "$grpname"
gid=`get_gid "$grpname"`
echo "${green}Group Added Successfully with group ID :${rev}${bold}${gid}${defColor}"
}

function edit_grp
{
clear
echo "1. ${rev}Change Group name${defColor} "
echo "2. Change Group ID$"
echo "3. ${rev}Back to main menu{defColor}"
read -p "Enter any option from [1-3]: " opt
if [[ "$opt" =~ ^[1-3]{1}$ ]];
then
case "$opt" in
1) grpname_change;;
2) grpid_change;;
3);;

esac
echo
echo
else
echo "${red}Invalid Input${defcolor}"
fi
}

function grp_assign
{
read -p "Enter the username which you want to assign to a group: " username
read -p "Enter the group name in which you want to assign the user: " groupname
usermod -a -G "$groupname" "$username"
echo "${green}USER ${bold}${username}${defColor}${green} has been assigned to ${bold}${groupname}${defColor}"
}

function grpuser_remove
{
read -p "Enter the username: " username
read -p "Enter the group from where you want to remove user: " groupname
deluser "$username" "$groupname"
}

function list_user
{
echo "${mag}${bold}The User list is${defColor}"
echo
cut -d: -f1 /etc/passwd | more
}

function list_grp
{
echo "${mag}${bold}The Group list is${defColor}"
echo
cut -d: -f1 /etc/group | more
}
clear
figlet Account Management
flag="Y"
while [ $flag == "Y" ]; do
echo "1. Add User "
echo "2. ${rev}Edit user ${defColor}"
echo "3. Delete User "
echo "4. ${rev}Add Group ${defColor}"
echo "5. Edit Group "
echo "6. ${rev}Delete Group ${defColor}"
echo "7. Assign Users to Group "
echo "8. ${rev}Remove Users From Group ${defColor}"
echo "9. List users "
echo "10.${rev}List groups ${defColor}"
echo "11.Exit "
echo
read -p "Enter any option from [1-11]: " opt
if [[ "$opt" =~ ^[0-9]+$ ]];
then

case "$opt" in
1) add_user;;
2) edit_user;;
3) del_user;;
4) add_grp;;
5) edit_grp;;
6) del_grp;;
7) grp_assign;;
8) grpuser_remove;;
9) list_user;;
10) list_grp;;
11) exit;;
esac
echo
echo
continue
else
echo "${red}Invalid Input${defColor}"
continue
fi
done
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.