i need help with a script.
#!/bin/bash # This process id pid=$$ # Path to the file which contains the process id path="/var/tmp/" # File which contains the process id file="accumRunning" pname="accumData" # Command for checking and running cmd="php /home/kersten/workspace/AdBenchImporter/import.php" # check if file exists if [ -s $path$file ]; then # Process id of the running command oldpid=`cat $path$file` # gets the parent id for the running script parent=`/bin/ps -lp $oldpid | tail -1 | tr -s ' ' | cut -c30- | cut -d' ' -f5;` # Checks if the current parent id matches the parent id of the running command if [ $parent = $pname ]; then echo "running" else `rm $path$file` `echo $pid > $path$file` `$cmd` fi else # writing the current proccess id in the file `echo $pid > $path$file` # Start the command `$cmd` fi exit 0
Above you can see my script. This is working very well if i start it in a console. It starts the process if it is not running and gives the answer that it is running if it finds the process id with the given pname.
Now i want to start it from a php script but it wont work. the process is started but the script gives me the wrong answer and it starts again.
Thanks for the help.