1

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.

closed as off-topic by Michael Homer, Shadur, roaima, Jeff Schaller, telcoM Feb 19 '18 at 15:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Michael Homer, Shadur, roaima, Jeff Schaller, telcoM
If this question can be reworded to fit the rules in the help center, please edit the question.

2

Does it really say

  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 &

? If so, there's a . missing, it should be tee ./output/[..], right?

Not the answer you're looking for? Browse other questions tagged or ask your own question.