2012-12-13 205 views
0

文件面向在讀線的問題這是一個輸入文件file1.txt從shell腳本

premon D0000070 0x201 0x40 

這是腳本。 script.sh

#!/bin/bash 
CommandFileName=$1 
while read line # This will read a line from file1.txt 
do 
    FileName="${line// /_}" 
    echo $FileName 

    cmviewer -- -u USUPPXY-0 -b --agent=DCHUP --buffer-size=250000 #this will hold a buffer of size 2.5MB 
    sleep 1 

    cmviewer -- -u USUPPXY-0 -m --agent=DCHUP # this will start monitoring 
    sleep 1 

    cmviewer -- -u USUPPXY-0 --up '$line' --agent=DCHUP 

    #this is the filtering condition // this should be replicate as a command ->  cmviewer -- -u USUPPXY-0 --up 'premon D0000070 0x201 0x40' #here I suspect $line is taking \n char aswell, so the command is not giving the desire output. #am I correct $line is taking new line char ? if it is so then how to remove it. 

    cmviewer -- -u USUPPXY-0 -s --agent=DCHUP #this will stop monitoring 
    sleep 1 

    cmviewer -- -u USUPPXY-0 -g --agent=DCHUP --dir=/root/ 
    # this will collect the logs in /root directory. - here I am getting 「Parsing error , premon D0000070 0x201 0x40 is not valid error」 # but when I execute the same command with out using script , it is working fine 

    #mv /root/*.BIN /root/$FileName 
    done < $CommandFileName 

希望我的問題是明確的..

回答

0

其實你的問題的心不是很清楚......但嘗試在該行

done < $CommandFileName; 

我結束移除分號不認爲它應該在那裏。^

0

很難確定你的問題是什麼,但我相信你正試圖從輸入文件中傳遞參數給cmviewer。嘗試:

while read args; do 
... 
cmviewer -- -u USUPPXY-0 --up $args --agent=DCHUP 
... 
done < $CommandFileName 

也就是說,傳遞參數給cmviewer時只是刪除引號。或者,也許你是想所有的參數傳遞作爲一個參數來cmviewer,在這種情況下,你必須用雙引號:

cmviewer -- -u USUPPXY-0 --up "$args" --agent=DCHUP 
+0

謝謝威廉..你的猜測是正確的..它的工作現在.. –