-1

I have a script which runs in sh shell, this script runs fine. But I've added one script written in ksh shell ( in the head of the script there is #!/bin/ksh) but every time i get the error

./monitor_FMn2.sh[19]: 104:  not found

Which every time change the second line that hit the error The 19th line is the line where i call the ksh script

if `wc -l < $LOGFILE` > 55;
    then
    logcycle $LOGFILE
fi

logcycle is the ksh script.

  • Where is your logcycle script, please specify the full path in your sh script, that is safer ... your sh cannot find the file in question. is logcycle executable ? – thecarpy Nov 29 '17 at 12:38
  • logcycle is based on a directory which is declared in PATH ( /home/oracle/FM2/scripts/logcycle) and is executable -rwxr-xr-x 1 oracle dba 2189 Nov 28 14:33 /home/oracle/FM2/scripts/logcycle. The sh script can find it, otherwhise i shouldn't have the error, right? – FaMontyN2 Nov 29 '17 at 12:42
  • Change logcycle to ksh /home/oracle/FM2/scripts/logcycle in your script, does that work ? – thecarpy Nov 29 '17 at 12:46
  • @thecarpy thanks for having a look. maybe i haven't been clear enough earlier, logcycle is in ksh already, is the other script that is not, it's in sh – FaMontyN2 Nov 29 '17 at 12:51
  • Please clarify, which line is which ? In fact, I think you should check Steephane's answer, I guess he is on track ... $LOGFILE had 104 lines when this error occurred, and the faulty line IS NOT logcycle $LOGFILE as your question implies but the if statement above that ... – thecarpy Nov 29 '17 at 12:57
2
`wc -l < $LOGFILE` > 55

Runs the command whose name is the output of wc subject to split+glob (104 in your case) and redirects its output to a file called 55 in the current directory. As there's no command called 104 on your system, you get that error.

Presumably, you wanted to write:

if [ "$(($(wc -l < "$LOGFILE") +0))" -gt 55 ]; then...

That is run the [ aka test command (instead of 104) to test that the output of wc -l interpreted as an arithmetic expression (so [ doesn't complain about leading spaces if any) is greater than 55.

Or with ksh syntax:

if (($(wc -l < "$LOGFILE") +0 > 55)); then...

(the +0 to cover for the case where the wc -l < "$LOGFILE" command produces no output, like when the $LOGFILE cannot be opened for reading).

(you may also want to remove that empty 55 file created earlier by your script).

  • thanks Stephane, i knew was a syntax error. I used the first option if [ "$(($(wc -l < "$LOGFILE")))" -gt 55 ]; then... and it work as i wanted. Many thanks indeed – FaMontyN2 Nov 29 '17 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.