I am migrating a legacy bash script which runs inside a www server. I have came across an issue that I am not able to explain.
When ran through the webserver (as a CGI included script), the following commands:
#!/bin/bash
set -e -u
echo "BP: Statistics generation 1" >/dev/fd/2
echo "BP: one: $1, two: $2" >/dev/fd/2
more ../download/interactions.$1.$2 | grep -v "#" | awk '($2!~/_R/){print $2}' | sort -k 1 | uniq > rna.names.txt
more ../download/interactions.$1.$2 | grep -v "#" | awk '($1!~/_R/){print $1}' | sort -k 1 | uniq > protein.names.txt
The protein.names.txt looks like:
../download/interactions.3424.asdfjj
507-558_1
::::::::::::::
The middle is the expected output but the first and the last line not. Neither of them are contained in the interactions.x.y file, which only contains a title in the beginning describing the columns and data. Test grep shows confirms that the data is not present.
The weirdest thing is that if I log in to the same machine and run the script from terminal (even su-ing as the www-data), the output is just the middle line, as it should be.
I have tried to export env and set from bash right before the said command and re-import them before running the script trying to recreate what is happening on the server, with no avail.
The script itself is not invoked directly, there is a CGI-included perl-script executing a system call to run the script via bash.
What is the source of that output? How can I at least reproduce it?