I'm trying to make a simple bash script to check for "php" process. If the spesific PHP script process (eg: cleanlog.php) does not run, it will then be executed from bash.
#!/bin/bash
var1=`ps -ef | grep -v grep | grep cleanlog| awk '{print $2}'`
echo $var1
if [ -n "$var1" ]
then
echo "Process running"
else
/usr/bin/php -q cleanlog.php
fi
When I tried to execute the bash script, it throws error:
line 9: syntax error near unexpected token `fi' line 9: `fi'
That could play a role if the script is not executed by using ./script , but for example sh script , otherwise the attempted use of the shell specified by the shebang would immediately throw an error on line 1... The script looks syntactically correct.
even posix - :). Same as RFC, there is lot of code makers who has not read those pages, starting from Seattle.
I have used so many *nix system which we have used in the our customers environment. I don't remember which env it was and I'm not interested. I'm interested that our scripts works without any modification in the every our customers *nix systems. There is lot of mainframe *nix envs which has not updated. As we know standards has written after many tools has done. Ex. many *nix still use ksh88, not ksh93, even 1993 was some years ago.
With tr I have found problem using \-escape sequences in history => We use always octal format.
It says using octal values is not portable because the octal values are codeset dependent. Since UNIX systems on mainframes usually use EBCDIC and UNIX systems on other boxes usually use a codeset that is a superset of ASCII, the octal character codes usually work on either EBCDIC based systems or on ASCII compatible systems, but not both. For example, the escape sequence representing the <newline> character ('\n') has the octal escape sequence value '\013' in ASCII, but '\045' in EBCDIC.
However, the octal code for the <carriage-return> character is the same in both ASCII and EBCDIC ('\015'), so (for the purposes of the above quote from the POSIX tr utility rationale) it is portable.
Note also that the quote goes all the way back to the original 1992 POSIX Shell and Utilities standard. I would have hoped that tr utilities on systems in use today all understand the \r escape sequence.