2014 the title of script.sh in the linux0218-4 of Ma Brothers

Source: Internet
Author: User
Tags stop script

Although this problem is not very difficult, but if the programming is not proficient, there are some challenges. Here thanks to my search for this friend, his problem-solving code to me a lot of reference, his blog is: http://sohudrgon.blog.51cto.com/3088108/1586780/


Write a script that accomplishes the following, using the following form:

script.sh {Start|stop|restart|status}

which

If the argument is empty, the Help information is displayed and the script exits;

If the argument is start, the file/var/lock/subsys/script is created and the starting script successfully is displayed.

If the parameter is stop, the file/var/lock/subsys/script is deleted and the stop script successfully is displayed.

If the parameter is restart, the file/var/lock/subsys/script is deleted and recreated, and then the restarting script successfully is displayed.

If the parameter is status, then:

If the file/var/lock/subsys/script exists, "script is running ..." is displayed, otherwise "script is stopped."


#!/bin/bash

#

Shname= ' basename

Filename= "/var/lock/subsys/$shName"


If [$#-ne 1];then

echo "Usage: $shName {start|stop|restart|status}"

echo "Please try again."

Exit 3

Fi

If ["$" = = "Start"];then

if! [-E $fileName];then

Touch $fileName && echo "Starting $fileName successfully."

Else

echo "$fileName already exists, try again." && Exit 4

Fi

elif ["$" = = "Stop"];then

If [-e $fileName];then

RM-FV $fileName && echo "Stop $fileName successfully."

Else

echo "$fileName does not exist, try again." && Exit 4

Fi

elif ["$" = = "Restart"];then

If [-e $fileName];then

RM-FV $fileName

Touch $fileName && echo "Restarting $fileName successfully."

Else

Touch $fileName

echo "Restarting $fileName successfully."

Fi

elif ["$" = = "Status"];then

If [-e $fileName];then

echo "$shName is running."

Else

echo "$shName is stopped."

Fi

Else

echo "Usage: $shName {start|stop|restart|status}"

echo "Please try again."

Exit 3

Fi



2014 the title of script.sh in the linux0218-4 of Ma Brothers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.