bash - shell script working fine on one server but not on another -
the following script working fine on 1 server on other gives error
#!/bin/bash processline(){ line="$@" # complete first line complete script path name_of_file=$(basename "$line" ".php") # seperate path name of file excluding extension ps aux | grep -v grep | grep -q "$line" || ( nohup php -f "$line" > /var/log/iphorex/$name_of_file.log & ) } file="" if [ "$1" == "" ]; file="/var/www/iphorex/live/infi_script.txt" else file="$1" # make sure file exist , readable if [ ! -f $file ]; echo "$file : not exists. script terminate now." exit 1 elif [ ! -r $file ]; echo "$file: can not read. script terminate now." exit 2 fi fi # read $file using file descriptors # $ifs shell variable. varies version version. known internal file seperator. # set loop separator end of line backupifs=$ifs #use temp. variable such $ifs can restored later. ifs=$(echo -en "\n") exec 3<&0 exec 0<"$file" while read -r line # use $line variable process line in processline() function processline $line done exec 0<&3 # restore $ifs used determine field separators ifs=$bakcupifs exit 0
i trying read file containing path of various scripts , checking whether scripts running , if not running them. file /var/www/iphorex/live/infi_script.txt
present. following error on amazon server-
[: 24: unexpected operator infinity.sh: 32: cannot open : no such file
thanks helps in advance.
you should initialize file
file=${1:-/var/www/iphorex/live/infi_script.txt}
and skip existence check. if file not exist or not readable, exec 0< fail reasonable error message (there's no point in trying guess error message be, let shell report error.)
i think problem shell on failing server not "==" in equality test. (many implementations of test accept 1 '=', thought older bash had builtin accepted 2 '==' might way off base.) eliminate lines file="" down end of existence check , replace them assignment above, letting shell's standard default mechanism work you.
note if eliminate existence check, you'll want either add
set -e
near top of script, or add check on exec:
exec 0<"$file" || exit 1
so script not continue if file not usable.
Comments
Post a Comment