I'm converting a script from csh to bash for use with a PBS batch job system, and I need to add commands which redirect stdout and stderr (hence the conversion to bash). What I'm after is not a simple case of using:
Code:
command_to_run $1 $2 $3 1> output.log 2> error.log
as I need to COPY the stdout and stderr to files and not just redirect.
My script processes multiple files via a single PBS batch job. Each file needs to have its own output and error log file (which the above code will do), but the single PBS job also needs to have the stdout and stderr output for each processed file put into its own output and error log file. The PBS batch job system uses stdout for its output log file and stderr for its error log file. I need to use the PBS error log file to check for any errors in the processed files, rather than going into each file's error log file (I'm dealing with thousands of files!). I don't want to have to create a separate script to consolidate the errors into a new file if the PBS error log file can provide this information with a small amount of coding.
I've done lots of searching to solve this but haven't had any luck. I'm new to bash, so it may be a case of me not fully understanding the coding.
What I require is:
1. copy the stdout results to 'output.log' for each processed file and keep the results in stdout so it can be picked up by the PBS batch job output results file.
2. copy the stderr results to 'error.log' for each processed file and keep the results in stderr so it can be picked up by the PBS batch job error results file.
Is there a way to have the std* go to both the *.log file and to the PBS log file?
In addition, I need to record the command line and arguments to a 'command_log' file. This currently happens with the csh file, but I can't work out the coding in bash. The csh script has the command:
Code:
alias GM 'echo \!* | tee -a log; echo; \!* >>! log1'
GM command_to_run $1 $2 $3
The alias GM is put before the commands I want to capture and enables the command line input and arguments to be put into the 'log' file and the stdout into the 'log1' file. All I want is to capture what's in the 'log' file.
Any advice would be greatly appreciated!!
Thanks in advance