#!/bin/bash clear #reading user and group id numbers from the passwd file while read ids do puid=$uid uid="$(echo $ids | cut -d: -f3)" gid="$(echo $ids | cut -d: -f4)" if [ $puid -le $uid ] then uid=$((uid+1)) gid=$((gid+1)) fi done < /etc/passwd #opening log file date=$(date) echo "MyFileSystem.txt opened. Date: $date" >> MyFileSystem.txt #function to get folder path of a user function foldername { while read myline do usern="$(echo $myline | cut -d: -f1)" foldn="$(echo $myline | cut -d: -f6)" if [ $usern = $username ] then echo $foldn path=$foldn fi done < /etc/passwd } echo "All your operations are save in a file called MyFileSystem.txt" #Main menu loop while : do echo " MAIN MENU " echo "1. Create New directory in a specified user's filesystem" echo "2. Add new user to the system in a specified home directory" echo "3. Delete User's filesystem" echo "4. Delete specified files from a specified user's filesystem" echo "5. Copy a file from a user to a different user" echo "6. Locate a file" echo "7. Print information for a user" echo "8. Print the network information" echo "9. Modify the permissions for a file/folder" echo "10. Open a Linux Terminal" echo "11. Add a user to a group" echo "12. Remove a user from a group" echo "13. Allow a user to rename a file" echo "14. Move user's file to another directory or filesystem" echo "15. Change the ownsership of a directory" echo "16. Quit" echo -n "Please enter your choice:" read opt case $opt in 1)#Getting the user name and the directory name and then creating the directory echo "Enter username" read username echo "Enter directory name" read dest_path foldername echo $path/$dest_path >> MyFileSystem.txt mkdir $path/$dest_path;; 2) #Getting all the information from the user and creating the user also saving the information in to the user_info file echo "Enter username" read username echo "Enter password" read password echo "Enter directory name" read directory echo "Enter the class name" read classname echo "Enter class number" read classno echo "Enter class time" read classtime newline=$username:$password:$uid:$gid::$directory/$username:$classname:$classno:$classtime echo $newline >> user_info echo $newline >> MyFileSystem.txt useradd -p $password -d $directory $username;; 3)#removing users filesystem looks it up in passwd with the username echo "Enter username" read username foldername echo $path >> MyFileSystem.txt rm $path;; 4)#removing a file from a users filesystem. Gets the filesystem path from the function above echo "Enter file name" read filename echo "Enter the username" read username foldername echo "rm $path/$filename" >> MyFileSystem.txt rm $path/$filename;; 5)#copying a file from a users directory to anywhere you want echo "Enter First username" read username echo "Enter the file name" read filename echo "Enter the destination path" read copyafile foldername echo $path/$filename $copyafile >> MyFileSystem.txt cp $path/$filename $copyafile;; 6)#finding a file in the system echo "Please enter the file name:" read search echo "find -name $search" >> MyFileSystem.txt find -name $search >> MyFileSystem.txt find -name $search;; 7)#showing user information both from /etc/passwd and user_info files echo "Enter username:" read username echo "From /etc/passwd:" echo `grep $username /etc/passwd` echo "From user_info file:" echo `grep $username user_info` echo "From /etc/passwd:" >> MyFileSystem.txt echo `grep $username /etc/passwd` >> MyFileSystem.txt echo "From user_info file:" >> MyFileSystem.txt echo `grep $username user_info` >> MyFileSystem.txt echo "";; 8) #showing network information ifconfig >> MyFileSystem.txt ifconfig;; 9)#changing permission of a file echo "Enter the file name to change permissions with the path" read chmodfile echo "Enter the permission" read permission echo "chmod $permission $chmodfile" >> MyFileSystem.txt chmod $permission $chmodfile;; 10)#opening terminal gnome-terminal;; 11) #assigning a user to a group echo "Enter the username" read usern echo "Enter the group name" read groupn echo "usermod -a -G $groupn $usern" >> MyFileSystem.txt usermod -a -G $groupn $usern;; 12)#taking a user out of a group echo "Enter the username" read username echo "Enter group name" read groupname echo "usermod -G $groupname $username" >> MyFileSystem.txt usermod -G $groupname $username;; 13)#chaning the ownership of a file to a user so he can move it and then moves it echo "Enter the username" read username echo "Enter the file name" read filename echo "Enter the new file name with the path" read newfilename foldername echo "chown $username $filename" >> MyFileSystem.txt chown $username $filename echo "mv $path/$filename $newfilename" >> MyFileSystem.txt mv $path/$filename $newfilename;; 14)#moving a file from a users directory to anywhere you want echo "Enter the username" read username echo "Enter the file name" read filename echo "Enter the new path and the file name" read newfilename foldername echo "mv $path/$filename $newfilename" >> MyFileSystem.txt mv $path/$filename $newfilename;; 15)#changing the ownership of a file echo "Enter the new user" read newuser echo "Enter directory with the path" read file echo "chown $newuser $file" >> MyFileSystem.txt chown $newuser $file;; 16)#Exiting the program newdate=$(date) echo "Exiting Program on $newdate" >> MyFileSystem.txt exit;; esac done