in bash script i have these relative lines:
find_time(){
args=( -A2 'Finished import for test' /var/apps/log/app.log )
while [ -z "$per_time" ] && [ $COUNTER -lt 3 ] ; do
if grep -q "${args[@]}" ; then
per_time=$(grep "${args[@]}" | grep Time)
output_time
elif ssh user@hostname grep -q -A2 'Finished import for test' /var/apps/log/app.log ; then
per_time=$(ssh user@hostname 'grep -s -A2 "Finished import for test" /var/apps/log/app.log | grep "Time"')
output_time
else
sleep 60
fi;
COUNTER=$((COUNTER+1))
done
echo "find_time OK"
}
output_time () {
time=${perf_time//[!0-9]/}
#convert to seconds and round the value
time=$(echo $time | sed 's/^\(.\{2\}\)/\1./' | awk '{ printf "%.1f\n",$1}')
echo -e "kpi5 : "$time" sec " >> "$result_file"
}
find_time
it gives me right result, however it shows in shell:
grep: import: No such file or directory
grep: for: No such file or directory
grep: test: No such file or directory
can not find out how to solve it.
You should put the whole command inside single quotes. So, I think you can try this one:
$(ssh user@host 'grep -A2 "Finished import for test " /var/apps/log/app.log | grep "Time"')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.