我运行一个ksh脚本并且里面有“echo”和“print”命令,这有点棘手 . 并且输出包含箭头符号 - > . 喜欢:
-> % Total % Received % Xferd Average Speed Time Time Time Current
-> Dload Upload Total Spent Left Speed
->
0 4374 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 4374 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
101 4374 0 0 101 4374 0 2934 0:00:01 0:00:01 --:--:-- 4072
100 4642 134 268 101 4374 152 2491 0:00:01 0:00:01 --:--:-- 3264
-> This is FLAG!!!
stty: standard input: Invalid argument
stty: standard input: Invalid argument
代码片段:它会在/data/home/user/bin/pushfile.sh /tmp/$ISSUE.$p4Cur $ RUN_ENV |的输出中生成 - > awk'{print“\ t”$ 0}'2>&1> $ tmpLog
#!/bin/ksh
if [[ $ENV != "production" ]]
then
. $HOME/bin/getenv $RUN_ENV >> $RUN_LOGFILE
if [[ ! -n $FILE_HOME ]]
then
echo "FILE_HOME could not be null"
exit 1
fi
cd $FILE_HOME
cat /tmp/$TICKET.$p4Cur | while read LINE
do
p4 sync -f "$LINE" 2>&1 > $tmpLog
rc=$?
cat $tmpLog | tee -a $RUN_LOGFILE
if [[ $rc -gt 0 ]]
then
echo "Failed to sync file"
exit $rc
fi
done
fi
if [[ $ENV != "production" ]]
then
echo "This is FLAG!!!"
/data/home/user/bin/pushfile.sh /tmp/$ISSUE.$p4Cur $RUN_ENV | awk '{print "\t" $0}' 2>&1 > $tmpLog
cat $tmpLog | tee -a $RUN_LOGFILE
errormsg=`grep "ERROR" $tmpLog `
erc=$?
if [[ $erc == 0 ]];then
echo "Failed to run /data/home/user/bin/pushfile.sh/tmp/$ISSUE.$p4Cur $BUILD_ENV ! script terminate!"
exit 1
fi
2 回答
也许这可能是解决方案;
先跑这个;
然后运行你的脚本;
在男人身上;
如果不工作,你能提供;
两个猜测:
$RUN_ENV
. 我们不知道那是什么 . Stdout被捕获到$RUN_LOGFILE
,stderr没有被分离并进入终端 .. $HOME/bin/getenv $RUN_ENV >> $RUN_LOGFILE
p4
(Perforce perchance?)重定向到$tmpLog
p4 sync -f "$LINE" 2>& 1 > $tmpLog
如果要将stdout和stderr捕获到文件中,请切换两个:
......
> $tmpLog 2>& 1
简而言之,有两个命令可以产生任何类型的输出搞乱你的屏幕 . 找出它是什么,并将该输出转移到适当的水槽 .