我有一个在调试模式下设置的脚本:
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
由于它处于调试模式,我得到的输出如下所述:
+ 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
我想保持终端干净并使用$LOGFILE
?在日志文件中打印脚本的所有调试信息。
答案1
您可以将输出重定向到任何文件,例如 log.txt
假设你的脚本名称是 test.sh
./test.sh > 日志.txt