bash: redirected file seen by script as 'does not exist ' -


i want check if there errors last command, hence redirecting stderr file , checking file "error" string.(only 1 possible error in case.)

my script looks below:

 #aquire lock   rm -f /some/path/err.out  myprogramme 2>/some/path/err.out &   if grep -i "error" /some/path/err.out ;     echo "error while running myprogramme, check /some/path/err.out error(s)"     #release lock               exit 1  fi 

'if' condition giving error 'no such file or directory' on err.out, can see file exists.

did miss ?.. appreciated. thanks!

ps: couldn't check exit code using $? running in background.

in addition file possibly not existing when call grep, call grep once, , sees whatever data in file. grep not continue reading file when reaches end, waiting myprogramme complete. instead, recommend using named pipe input grep. cause grep continue reading pipe until myprogramme does, in fact, complete.

#aquire lock  rm -f /some/path/err.out p=/some/path/err.out mkfifo "$p" myprogramme 2> "$p" &   if grep -i "error" "$p" ;    echo "error while running myprogramme, check /some/path/err.out error(s)"    #release lock              exit fi 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -