1

This question already has an answer here:

I am having a script which i have set in the debug mode:

set -x
#!/bin/sh

ALLCIRCLS="/var/tmp/release/ALLCIRCLS.txt"
NONRBTIPS="/var/tmp/release/NONRBTIP.txt"
RBTIPS="/var/tmp/release/RBTIPS.txt"
NONRBTIPGNOCIP="/var/tmp/release/NONRBTIPGNOCIP.txt"
NONRBTROOTIP="/var/tmp/release/NONRBTROOTIP.txt"
LOGFILE="/var/tmp/release/log_result.log"
release="/var/tmp/deployment/*"

for IP_ADDRESS in $(cat $NONRBTIPS); do
   echo "TEST FOR ${IP_ADDRESS}" >> $LOGFILE
   scp -r /var/tmp/deployment/* test@${IP_ADDRESS}:/var/mnt/promptbase/prompts/local_cms >> $LOGFILE
   if [ $? -ne 0 ] ; then
      echo "Secure copy is failed " >> $LOGFILE
      exit 1
   else
      echo "Secure copy is successfull"
   fi
done

As it is in debug mode I am getting output as described below:

+ ALLCIRCLS=/var/tmp/release/ALLCIRCLS.txt
+ NONRBTIPS=/var/tmp/release/NONRBTIP.txt
+ RBTIPS=/var/tmp/release/RBTIPS.txt
+ NONRBTIPGNOCIP=/var/tmp/release/NONRBTIPGNOCIP.txt
+ NONRBTROOTIP=/var/tmp/release/NONRBTROOTIP.txt
+ LOGFILE=/var/tmp/release/log_result.log
+ release='/var/tmp/deployment/*'
++ cat /var/tmp/release/NONRBTIP.txt
+ for IP_ADDRESS in '$(cat $NONRBTIPS)'
+ echo 'TEST FOR 172.19.117.198'
+ scp -r /var/tmp/deployment/ID_MB4_W2JUL19 test@172.19.117.198:/var/mnt/promptbase/prompts/local_cms

I would like to keep my terminal clean and print all the debugging of the script in the log file using $LOGFILE?

marked as duplicate by muru, Community Jul 18 at 7:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • The shebang line (#!/bin/sh) must be the first thing in the file. You should either put set -x after it, or use #!/bin/sh -x. – Gordon Davisson Jul 18 at 7:34
  • ok thanks for the correction. – Arun Doddi Jul 19 at 9:47
0

You can redirect the output any file let's say log.txt

assumption your script name is test.sh

./test.sh > log.txt

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