My first shell script

colored-man
Well, after installing arch linux, i had to install the usual tools i need to get my work done, one of these tools is the localhost server that consists of apache,mysql,php … etc, So what i love about arch linux that is i control everything, i don’t want the apache and mysql deamons running all the time or start when the OS starts, it makes the boot time longer, so as i’ve used to, i run the deamons when i need them then turn them off afterwards. To prove to myself that i am smart “lol!” i decided to write a shell script that allows me to start, restart or stop those services easily, and yay i did it !

op=$1
if [[ "$op" = "start" ]]
then
    sudo systemctl start mysqld
    sudo systemctl start httpd
    echo "Web server started..."
elif [[ "$op" = "restart" ]]
then
    sudo systemctl restart mysqld
    sudo systemctl restart httpd
    echo "Web server has been restarted..."
elif [[ "$op" = "stop" ]]
then
    sudo systemctl stop mysqld
    sudo systemctl stop httpd
    echo "Web server stopped..."
else
    echo "Wrong argument, add one of these argument after
webserver.sh: start, restart or stop. eg: ./webserver.sh start"
fi

the script is pretty easy, it just consists of some conditions and the variable that should be written after the script name. It gives an error when the user doesn’t write any operation to be done. It’s not a sophisticated script but as a first script, i like it very much 😀

Advertisements

One thought on “My first shell script

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s