#!/bin/bash #Define the shell the script should run in case $1 in # $1 is the first command line arguement, script start or script stop start) # here is where the start block begins, ;; is where it will end if [ -f /full/path/to/cod_lnxded ];then # this will test that your binary is where # you say it is, "man test" /full/path/to/cod_lnxded > /tmp/cod.log 2>&1 & #run cod_lnxded, throw away #any output including std # err and backgroud it echo $? > /tmp/cod.pid # here's what you wanted to know, create a file named # cod.pid that contains the pid echo "hit ctrl-c to exit log" #this will make sense due to the next line /usr/bin/tail -f /tmp/cod.log #this is a trick to immediately check the log file #while the script is starting the binary fi # This ends the test ## Note: Similar to the stop you can check if the process is running first, ## but I left this out for you to figure out. That is a good idea so you ## don't start two by accident ;; stop) # same code as the start and it will end with ;; if [ -f /tmp/cod.pid ];then #check to see if pid file exists /usr/bin/ps -p `cat /tmp/cod.pid` # Back ticks will run a sub command to # send actual pid to the "ps" command if [ $? = 0 ];then # this will check if the last process, our ps, ran successfully # and found a running process with that pid /usr/bin/kill -9 `cat /tmp/cod.pid` # this will forcefully kill the # pid using the same technique else echo "No running COD" # this just prints if test ps turned out false exit 1 # forces to stop, printing an error code properly fi # end running proc test else echo "/tmp/cod.pid not found" # This just prints if the test on the file # was false exit 1 # forces stop because pid file wasn't found fi # end of pid file test ;; status) if [ -f /tmp/cod.pid ];then /usr/bin/ps -ef | grep `cat /tmp/cod.pid` #use this to check status to see if #process is still running #similar you can make a restart block that #checks if the file exists and the #process is running. Add this to cron #once a minute just in case the process #dies then cron will start it for you fi ;; *) #this is a block that tells users how to run the script, if they type argument $1 as # anything but start, stop, status, and what ever else you write, the script exits with # an error but prints out how to use the script properly echo "Usage: (start|stop|status) exit 1 ;; esac # this ends the case statment, case spelled backwards ## WARNING: This script wasn't tested and should not be ## used for transfering money or where human life maybe ## at stake. For your own safety run at your own risk. ## Improper usage may cause bodily harm. I assume no responsibility :) ## and my spelling might be off in my comments enjoy, cross your fingers