这是输入文件file1.txt
:
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 :(得分:0)
实际上你的问题不是很清楚......但是尝试删除行尾的分号
done < $CommandFileName;
我不认为应该在那里。 ^
答案 1 :(得分: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