![](/img/trans.png)
[英]Return to linux command line prompt after executing an HBase shell script
[英]Executing command remotely on another linux server from a shell script
我有一個shell腳本,該腳本從兩個日期之間的日志文件中提取詳細信息,並在輸出上執行命令以生成一些報告。 日志文件在不同的服務器上,腳本在不同的服務器上執行。 腳本看起來像:
#!/bin/sh
time1=$1
time2=$2
echo `ssh -i key user@ip -yes cat file | awk '{if(substr($4,2)>="'$time1'" && substr($4,2)<="'$time2'") print $0;}'` > tmp.log
`cat tmp.log | some operation to get detail`
輸出應該在多行中,例如:
ip1 date1 - - request1 file1 method1 status1
ip2 date2 - - request2 file2 method2 status2
但是(通過我的命令)生成的輸出被合並為一行,其中包含所有詳細信息,例如:
ip1 date1 - - request1 file1 method1 status1 ip2 date2 - - request2 file2 method2 status2
當命令直接在服務器上執行時,它會生成所需的輸出,但在遠程執行時則不會生成。
所以我的問題是我將如何獲得正確的輸出,這是實現這一目標的好方法嗎?
從上面的評論中,您仍在使用“ echo”。 @tripleee是正確的。 別。 也不要在一開始就使用毫無意義的貓-只需將std重定向到您的下一個命令即可。
#!/bin/sh
time1=$1
time2=$2
ssh -i key user@ip -yes cat file | awk '{if(substr($4,2)>="'$time1'" && substr($4,2)<="'$time2'") print $0;}' > tmp.log
some operation to get detail <tmp.log
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.