LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash Script Assistance (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-assistance-4175560247/)

jkeeton81 11-30-2015 04:07 PM

Bash Script Assistance
 
Hello,

I am in a Unix class and have been out of town so I missed some lectures. I have been tasked to generate a couple of scripts and ahve never done it before. I have a virtual machine running Ubuntu. The task is below

Prompt the system administrator for all valid input parameters
Generate a menu to ask which task is needed to be performed
Create a UNIX group
Drop a UNIX group
Create a user
Drop a user

Prompt the system administrator for the target user name
List the running processes for that user
Confirm with the system administrator before killing the processes
Kill the processes after confirmation

I understand the commands to create users and groups and to kill processes, but I do not know how to write a scrpt to perform all of this and prompt the admin/generate menus

Any help would be greatly appreciated

jmgibson1981 11-30-2015 04:09 PM

http://www.tldp.org/LDP/Bash-Beginners-Guide/html/

you will not find people doing homework for you typically on linux forums.

Habitual 11-30-2015 04:35 PM

write functions or if simple enough, use direct commands.
Then write a "menu" to present those choices.
Menu choices call the function(s)

Code:

remove_user() #I am a function
{
# stuff here to do stuff
)

echo ""
echo "This is my menu"
echo "==============="
echo "choice0"
echo "choice1"
echo "choice2"
echo "choice3"
echo "Please choose an option"
case choice in
    create_group)
        call function or do stuff
    delete_group)
        call function or do stuff
    create_user)
        call function or do stuff
    delete_user)
        remove_user # calls the function remove_user
    *)
        exit
esac

It's far from perfect. A generalized outline...

http://wiki.bash-hackers.org/syntax/ccmd/case
http://tldp.org/LDP/abs/abs-guide.pdf
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-8.html

Have fun and Good Luck!

berndbausch 11-30-2015 04:35 PM

Quote:

Originally Posted by jmgibson1981 (Post 5457566)
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/

you will not find people doing homework for you typically on linux forums.

BashGuide and BashFAQ on http://mywiki.wooledge.org are very useful as well.

chrism01 11-30-2015 06:01 PM

If you google 'bash menu select' you'll get some good examples.
eg https://askubuntu.com/questions/1705...a-shell-script

As above, definitely use a function for each task.

jkeeton81 11-30-2015 09:10 PM

Thank you guys, I was not asking for someone to do it for me. Just a direction on how to add things such as the comments. Those links should do good for me.

Thank you again

Habitual 11-30-2015 09:31 PM

Glad to be of help.

Make us all proud!


All times are GMT -5. The time now is 11:38 AM.