我整个早上都在研究这个问题,但没有运气。我需要结果全部在一行逗号分隔上。有些部分工作正常,但一旦我添加了阅读,它就感觉分开了!
INPUT=steamIPs.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read router contact address
do
myvar="$ip
$router
$contact
$address"
echo "$myvar" | paste -s -d','
OUTPUT=`snmpget $ip -c public -v 1 sysuptim`
echo ${OUTPUT#*:} | tr -d ' '
done < $INPUT
IFS=$OLDIFS
你太努力了:
if [[ ! -f "$INPUT" ]]; then
echo "$INPUT file not found"
exit 99
fi
while IFS=, read -r router contact address; do
myvar="$ip,$router,$contact,$address"
echo "$myvar"
done < "$INPUT"