Shell script not running correctly

I’ve got strange issue with simple shell script that I want to ouptut result to textfile which I will use later for reading some content.

shell script

#!/bin/sh
for file in $(find -name .curlrc ); do
grep -q “curl -k” $file
if [ $? -eq 0 ]; then
echo “‘curl -k’ |found in file| "$file"”
else
echo “‘curl -k’ |not found in file| "$file"”
fi
done

command to run from bigfix
wait chmod +x “/var/tmp/findcurlrc”
wait /bin/sh “/var/tmp/findcurlrc” >> “/var/tmp/findcurlrc.txt”

Checking the client logs not seeing any errors
Command started - wait chmod +x “/var/tmp/findcurlrc” (action:3685886)
Command succeeded (Exit Code=0) wait chmod +x “/var/tmp/findcurlrc” (action:3685886)
At 15:24:06 +0000 - actionsite (http://bfixroot.pg.com:29450/cgi-bin/bfgather.exe/actionsite)
Command started - wait /bin/sh “/var/tmp/findcurlrc” >> “/var/tmp/findcurlrc.txt” (action:3685886)
Command succeeded (Exit Code=0) wait /bin/sh “/var/tmp/findcurlrc” >> “/var/tmp/findcurlrc.txt” (action:3685886)
At 15:24:06 +0000 -
ActionLogMessage: (action:3685886) ending action

Issue I’m facing is that the textfile /var/tmp/findcurlrc.txt is not getting created.
when i run the script from the server directly it works just fine and text file is created.

I’ve also tried below approach but same result

#!/bin/sh
for file in $(find -name .curlrc ); do
grep -q “curl -k” $file
if [ $? -eq 0 ]; then
echo “‘curl -k’ |found in file| "$file"” >> “/var/tmp/findcurlrc.txt”
else
echo “‘curl -k’ |not found in file| "$file"” >> “/var/tmp/findcurlrc.txt”
fi
done

Any help/suggestions are welcome

Thx!

The output redirection is a function of the shell, but the ‘wait’ command is not a shell itself, and the output redirection you have needs to be explicitly passed as a parameter to /bin/sh instead of ‘wait’ trying to handle it.

It’s just a matter of quoting the sh command line, I think. Try

wait /bin/sh "'/var/tmp/findcurlrc' >> '/var/tmp/findcurlrc.txt'"

This wraps the entire shell command line including output redirection in a set of double quotes, and changes embedded quotes into single quotes.
Alternatively you could probably use backslash to escape embedded double quotes as in

wait /bin/sh "\"/var/tmp/findcurlrc\" >> \"/var/tmp/findcurlrc.txt\""

Another possibility worth mention is that some security policies might block executing commands or scripts from /tmp paths.