Und hier noch mit den Parameter als Übergabe ans Programm!
./runner.sh Programm_Name Voller_Pfad_zum_Programm Flag_file_Name
PHP Code:
#!/bin/sh
if [ -z $1 ] || [ -z $2 ] || [ -z $3 ] ; then
echo -e "Wrong Usage!\nUsage: $0 PROG_NAME FULL_PROG_PATH FLAG_FILE"
return 3
fi
# if flag file exists, check also the process via ps
CHECK_ALSO_PROCESS=1
# program details
FETCH_PROG=$1
FULL_PROG=$2
FLAG_FILE=$3
# is the program running or not, default = NO == 1 - dont touch this!
RUN_PROG=1
# if file exists, check the process
if [ -f $FLAG_FILE ] ; then
# if file exists, check if we want to look for the process via ps
if [ $CHECK_ALSO_PROCESS -eq 1 ] ; then
# dont grep the grep cmd and also not the scripts name, because the fetch program name is a parameter
catch=`/bin/ps | grep $FETCH_PROG | grep -v grep | grep -v $0 -c`
# if it is greater than 1, then the program is running - nothing todo
if [ $catch -ge 1 ] ; then
RUN_PROG=0
else
echo "Flag file ($FLAG_FILE) exists, but program ($FETCH_PROG) is not running! Program will be executed!"
fi
fi
fi
# if program should be executed
if [ $RUN_PROG -eq 1 ] ; then
touch $FLAG_FILE
echo "Starting program: $FULL_PROG"
$FULL_PROG
# remove the flag file
rm $FLAG_FILE
# return not 0, because its an error
else
return 2
fi