UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old March 29th, 2008, 11:28 AM
ad4m88 ad4m88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Manchester, UK
Posts: 7 ad4m88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 41 sec
Reputation Power: 0
Menu Driven UNIX Admin

Hiya there all, I am newbie to UNIX.

How would i write a script in a bash shell that can:
a) reboot the box
b) prefix a reboot with a suitable warning and pause
c) ping an IP address specified by the user and report on the response
d) kill a processes as specified by the user
e) add and delete a user

Hope someone can help or guide me to some good resources.

Thanks for your time.

Kind Regards
Ad4m88

Reply With Quote
  #2  
Old March 29th, 2008, 03:27 PM
Edvallie Edvallie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Kalamazoo, MI
Posts: 36 Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 20 m 33 sec
Reputation Power: 12
Send a message via AIM to Edvallie
Quote:
Originally Posted by ad4m88
Hiya there all, I am newbie to UNIX.

How would i write a script in a bash shell that can:
a) reboot the box
b) prefix a reboot with a suitable warning and pause
c) ping an IP address specified by the user and report on the response
d) kill a processes as specified by the user
e) add and delete a user

Hope someone can help or guide me to some good resources.

Thanks for your time.

Kind Regards
Ad4m88


You can do most of those with a single bash command, no need to write a script to do it... If you want to put it into a script for the sake of a cronjob, simply put the command in a text file with #!/bin/bash on the first line.

A) command is 'reboot'
B) I think there is some kind of flag you can pass to the reboot command to do it after a certain amount of time. ('man reboot' in console)
C)'ping ipaddress'
D)kill -9 PID
E) 'deluser' and 'adduser' should be pathed to work if you're logged in as root for deleting and adding users, on most nix systems.

Sorry, didn't read the menu driven part in the topic. If it really needs to be menu driven, the bash script wouldn't be too hard to write. Start off with echo'ing different numerical values to screen and the corresponding task they do. Use if/else to parse through the different numerical values that the script prompts for and have it execute the command.

Could be done easily this way as well:
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-9.html#ss9.1

Reply With Quote
  #3  
Old March 29th, 2008, 03:36 PM
ad4m88 ad4m88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Manchester, UK
Posts: 7 ad4m88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 41 sec
Reputation Power: 0
Thanks a lot for your help.

Hope not asking for too much from you, but in a script, how could I do it so the user can for example enter an IP address, and then it pings that IP address, or the user states he wants to kill a certain process and that process is killed?

I have done most of the menu driven script, where the user simply selects [1-7] to do different things, e.g. memory usage, date, cal etc.... but can’t seem to do for when a user can enter (as above, maybe an IP address) then the script runs.

Hope you understand.

Thanks once again for helping earlier.

Best Regards
P.S. I tried sending you a pm, but couldn’t for some reason, to show you my script so far...

Reply With Quote
  #4  
Old March 29th, 2008, 03:46 PM
Edvallie Edvallie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Kalamazoo, MI
Posts: 36 Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 20 m 33 sec
Reputation Power: 12
Send a message via AIM to Edvallie
Quote:
Originally Posted by ad4m88
Thanks a lot for your help.

Hope not asking for too much from you, but in a script, how could I do it so the user can for example enter an IP address, and then it pings that IP address, or the user states he wants to kill a certain process and that process is killed?

I have done most of the menu driven script, where the user simply selects [1-7] to do different things, e.g. memory usage, date, cal etc.... but can’t seem to do for when a user can enter (as above, maybe an IP address) then the script runs.

Hope you understand.

Thanks once again for helping earlier.

Best Regards
P.S. I tried sending you a pm, but couldn’t for some reason, to show you my script so far...



echo "Enter IP To Ping:"
read IP
ping $IP

Same idea for killing a process:

echo "Enter PID:"
read THEPID
kill -9 $THEPID

Reply With Quote
  #5  
Old March 29th, 2008, 04:20 PM
ad4m88 ad4m88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Manchester, UK
Posts: 7 ad4m88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 41 sec
Reputation Power: 0
Thanks alot mate ... you really know your stuff.

How could i check a user exists on the system then change their password? And provide a summary of details for a user such as : the number of files in their
home directory, details of when they last logged on, total disk space used by the user, number of processes currently running, details of the groups they belong to etc ..

Hope you don't mind.

Thanks alot for your help anywayz.

Regards

Reply With Quote
  #6  
Old March 29th, 2008, 04:23 PM
ad4m88 ad4m88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Manchester, UK
Posts: 7 ad4m88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 41 sec
Reputation Power: 0
How would i ping a list of host addresses which are in a file, without typing each one.

Reply With Quote
  #7  
Old March 30th, 2008, 12:21 AM
Edvallie Edvallie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Kalamazoo, MI
Posts: 36 Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 20 m 33 sec
Reputation Power: 12
Send a message via AIM to Edvallie
Quote:
Originally Posted by ad4m88
How would i ping a list of host addresses which are in a file, without typing each one.


Took me a couple bouts, but this should work: format for hostsfile is a plaintext doc with ip's or hostnames seperated by spaces.

msgln=`cat hostsfile |strings |awk '{print NF}'`
let msgln=msgln+1
COUNTER=1
while [ $COUNTER -lt $msgln ]; do
ping `cat hostsfile |strings |awk '{print $'$COUNTER'}'`
let COUNTER=COUNTER+1
done


Quote:
Originally Posted by ad4m88
Thanks alot mate ... you really know your stuff.

How could i check a user exists on the system then change their password? And provide a summary of details for a user such as : the number of files in their
home directory, details of when they last logged on, total disk space used by the user, number of processes currently running, details of the groups they belong to etc ..

Hope you don't mind.

Thanks alot for your help anywayz.

Regards


Sounds like I'm starting to do your job for you

I'd suggest looking into these aspects for actually writing it:
finger/grep/passwd

It shouldn't be too hard to piece something together, there are a lot of good bash docs on google.

Reply With Quote
  #8  
Old March 30th, 2008, 06:58 AM
ad4m88 ad4m88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Manchester, UK
Posts: 7 ad4m88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 41 sec
Reputation Power: 0
Sorry bout that ... but thnxs alot for your help. Really appreciate it.

Reply With Quote
  #9  
Old March 30th, 2008, 10:26 AM
ad4m88 ad4m88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Manchester, UK
Posts: 7 ad4m88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 41 sec
Reputation Power: 0
Sorry ... but one last question.

You know when I asked in the first post how to have a script that can do an automated IPL function (how to reboot the box). You state ‘reboot’ would do the trick.

How would I go about doing it, for example if the user states from a menu script that I would like to reboot now. The problem is when I do the ‘reboot’ command I get a message (obviously) because I am not the super user. But I do have another gem network in which I have root superuser access.

So how would I from the below script which I need to write whilst I am not in super user mode do the ‘reboot’ command (and add/delete user command) from the normal user mode.

Is there a way of having, for example when the user chooses option 1, then it states enter the other gem network root username and password and then be able to do the ‘reboot’ (& adduser) command?

I hope I have not made it difficult to understand for you.

P.S. I have cut out alot of the code so it wasier for you to see.

Reply With Quote
  #10  
Old March 30th, 2008, 04:05 PM
Edvallie Edvallie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Kalamazoo, MI
Posts: 36 Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level)Edvallie User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 20 m 33 sec
Reputation Power: 12
Send a message via AIM to Edvallie
Quote:
Originally Posted by ad4m88
Sorry ... but one last question.

You know when I asked in the first post how to have a script that can do an automated IPL function (how to reboot the box). You state ‘reboot’ would do the trick.

How would I go about doing it, for example if the user states from a menu script that I would like to reboot now. The problem is when I do the ‘reboot’ command I get a message (obviously) because I am not the super user. But I do have another gem network in which I have root superuser access.

So how would I from the below script which I need to write whilst I am not in super user mode do the ‘reboot’ command (and add/delete user command) from the normal user mode.

Is there a way of having, for example when the user chooses option 1, then it states enter the other gem network root username and password and then be able to do the ‘reboot’ (& adduser) command?

I hope I have not made it difficult to understand for you.

Code:
echo "-------------------------------------"
echo " UNIX Menu Driven Administration"
echo "-------------------------------------"
echo "1. Automated IPL Function"
echo "2. Add User"
echo "3. Network Check"
echo "4. System Information"
echo "====================================="
echo "Make Your Selection: "
        read menunumber

         if [ $menunumber -eq 3 ]

                then
                        echo " NETWORK CHECK "
                        echo "-------------------------------------"
                        echo " NETWORK CHECK ">>report.txt
                        echo "-------------------------------------">>report.txt
sleep 1
                        echo " Your IP Address is: $IPAddress"
                        echo "-------------------------------------"
                        echo " Your IP Address is: $IPAddress">>report.txt 
                        echo "-------------------------------------">>report.txt
sleep 1 
                        echo " Enter IP To Ping:"
                        read IP
                        /bin/ping $IP  -w 2 > /dev/null 
                        if [ $? = 0 ] ; then 
                                        echo "-------------------------------------"  
                                        echo "Machine $IP is on the network"
                                        echo "Machine $IP is on the network">>report.txt
                        else 
                                        echo "-------------------------------------"
                                        echo "Machine $IP is not on the network"
                                        echo "Machine $IP is not on the network">>report.txt
                        fi 
                        echo "-------------------------------------"
                        echo "-------------------------------------">>report.txt


P.S. I have cut out alot of the code so it wasier for you to see.


either run the script as root or "sudo reboot" or "su -c reboot" if you have the root pw.

Reply With Quote
  #11  
Old March 31st, 2008, 04:27 AM
ad4m88 ad4m88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Manchester, UK
Posts: 7 ad4m88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 41 sec
Reputation Power: 0
I cant run it on root whilst in my current script, but i have admin access to another gem network. However this is not too secure and therefore it is not wise to run and save the full script in there.

Is there a way of having, when the user chooses option 1, then it states enter the other gem network root username and password and then be able to do the ‘reboot’ (& adduser) command from there. But once reboot is done i can go back to the network i am working on.

P.S. sudo reboot requires the root password for the network i am currently working on, but i dont have a pw for this. (Hope not confused you)

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Menu Driven UNIX Admin


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |