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