I've got a script that runs a number of curl commands by reading an input file line by line (each line has different curl parameters). I'm trying to tee the stnd out and stnd error of the curl command to a log file as well as display them to the terminal. Simple, right?
But for some reason tee will not save the output to the subdirectory where I want the log file. It will create the log file if I specify the directory the script is running in.
Below is the relevant code:
if [[ -f $1 ]]
then
echo "Running requests from $1"
bname=`basename ${1} | awk -F\. '{print $1}'`
mkdir ./output/${bname}
echo "Will write output to ./output/${bname}"
while read line
do
let j=j+1
post_data=`perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "${line}"`
echo $line > ./output/${bname}/${bname}_${j}_request
curl -v -b cookie ${SvrProperties} -d "xmlrequest=$post_data" -o ./output/${bname}/${2}_${j}_response.xml 2>&1 | tee /output/${bname}/${2}_${j}_Run.log &
done < ${1}
elif [[ -d $1 ]]
then
for file in `ls $1`
do
echo "Running requests from $1/${file}"
bname=`basename ${file} | awk -F\. '{print $1}'`
mkdir ./output/${bname}
echo "Will write output to ./output/${bname}"
while read line
do
let i=i+1
post_data=`perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "${line}"`
echo $line > ./output/${bname}/${bname}_${i}_request
curl -v -b cookie ${SvrProperties} -d "xmlrequest=$post_data" -o ./output/${bname}/${2}_${i}_response.xml 2>&1 | tee /output/${bname}/${2}_${i}_Run.log &
done < ${1}/${file}
done
else
echo "Invalid input, neither file nor directory! Exiting..."
exit
fi
Note: The line where I echo the request to the subdirectory as well as saving the output of the curl request all work. It's only the tee command that doesn't work.
The log files will be created if I write something like this:
curl -v -b cookie ${SvrProperties} -d "xmlrequest=$post_data" -o ./output/${bname}/${2}_${j}_response.xml 2>&1 | tee ${2}_${j}_Run.log &
But then it's not in the location that I want.