I have a shell script like this.
line="$@" # get the complete first line which is the complete script path
name_of_file = ${line%.*}
file_extension = ${line##*.}
if [ $file_extension == "php"]
then
ps aux | grep -v grep | grep -q "$line" || ( nohup php -f "$line" > /var/log/iphorex/$name_of_file.log & )
fi
if [ $file_extension == "java"]
then
ps aux | grep -v grep | grep -q "$line" || ( nohup java -f "$name_of_file" > /var/log/iphorex/$name_of_file.log & )
fi
here line variable has values like /var/www/dir/myphp.php or /var/www/dir/myjava.java.
The purpose of shell script is to check if these processes are already running and if not i try to run them.I get the following errors.
name_of_file: command not found
file_extension: command not found
[: missing `]'
[: missing `]'
Any ideas?
Firstly, the shell processor treats the line:
as the execution of the command:
with the parameters:
you need to write it as:
This makes it into a variable=value. You need to repeat this for the file_extension = line as well.
Secondly, the if:
has exactly the same parsing problem, you must have a space before the trailing ], because otherwise the parser thinks you’re checking if $file_extension is equal to the string: “php]”