A Simple Bash Script To Manage Linux Services

                         This is a simple script to manage all the system services in your Linux operating system. The script can interact with the user and manage the services in the linux OS. With the help of this simple bash script you can start, stop, reload, and know the current status of all the services in your server like Squid, Samba, postfix, dovecot, apache, FTP, VNC, DHCP, NFS, iptables, etc. All you need to select the task and input the exact service name(daemon name). And the script will do the task.

For example if you need to reload the squid service, first run the script and select "4" (for reloading a service), and type the service name "squid". Now the script will reload the squid service for you. You can edit the script and add more options as your needs.
This script is tested in CentOS and should work on RPM based distributions like Fedora and Redhat Linux, etc.

How to create Bash Script
[root@server ~] vim servicemanager
#Add the below text (green in colour) into the new file
#!/bin/bash
clear
selection=
service=
until [ "$selection" = "5" ]; do
echo "------------ -------------- ------------"
echo "Welcome System Service Managing Script"
echo "------------ -------------- ------------"
echo "1: To know the status of a service"
echo "2: To start a service"
echo "3: To stop a service"
echo "4: To reload a service"
echo "5: Exit"
echo -n "Enter your menu selection>"
read selection
        if [ "$selection" = "5" ]; then
        echo "Bye, Exiting Script....." $exit
        else
echo -n "Enter service name>"
read service
        fi
        case $selection in
        1 ) service $service status ;;
        2 ) service $service start ;;
        3 ) service $service stop ;;
        4 ) service $service reload ;;
        5 ) echo "Have a great Day." $exit ;;
        * ) echo "$selection is an invalid option"
        esac
done
#Now save the file and exit from the editor.


Set Execute permission
[root@server ~] chmod 755 servicemanager


Run the Bash Script
[root@server ~] ./servicemanager
#(The sample output is displayed in the below screenshot. In the example screenshot i stopped the smb service(Samba daemon) with the help of bash script.)



Thanks for visiting, post your comments......

0 comments:

Related Posts Plugin for WordPress, Blogger...

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Coupons