LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-30-2015, 04:07 PM   #1
jkeeton81
LQ Newbie
 
Registered: Nov 2015
Posts: 2

Rep: Reputation: Disabled
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
 
Old 11-30-2015, 04:09 PM   #2
jmgibson1981
Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 371

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

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

Last edited by jmgibson1981; 11-30-2015 at 04:10 PM.
 
Old 11-30-2015, 04:35 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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!

Last edited by Habitual; 11-30-2015 at 04:40 PM.
 
Old 11-30-2015, 04:35 PM   #4
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,456

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Quote:
Originally Posted by jmgibson1981 View Post
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.
 
Old 11-30-2015, 06:01 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,670

Rep: Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487
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.
 
Old 11-30-2015, 09:10 PM   #6
jkeeton81
LQ Newbie
 
Registered: Nov 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
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
 
Old 11-30-2015, 09:31 PM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Glad to be of help.

Make us all proud!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Need Assistance with a Bash script for Ceaning Home Directories Joseph4200 Programming 2 07-25-2011 12:29 PM
BASH assistance - loop/counter rickenbacherus Programming 6 03-12-2007 05:34 PM
need assistance with this script rsmccain Linux - General 2 02-08-2007 10:41 PM
Bash assistance Ateo Programming 5 03-08-2005 11:58 PM
bash assistance requested.. Ateo Programming 3 02-09-2005 06:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration