1

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 [email protected]:/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?

2
  • 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. Commented Jul 18, 2019 at 7:34
  • ok thanks for the correction.
    – Arun Doddi
    Commented Jul 19, 2019 at 9:47

1 Answer 1

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 .