Reputation: 559
I am using the bash script below to get these values from my server and I want to text these to myself. The only problem is when it runs it does something like in java println rather than print.
How can I put the response all on the same line like
1.3.6.1.2.1.1.2 = STRING: "Dell Lat i17" 1.3.6.1.2.1.1.4 = STRING: "888.888.1234"
rather than the output below?
Input:
OUTPUT=`snmpget 172.0.0.1 -c public -v 1 1.3.6.1.2.1.1.2 1.3.6.1.2.1.1.4 1.3.6.1.2.1.1.6'
echo $OUTPUT
Output:
1.3.6.1.2.1.1.2 = STRING: "Dell Lat i17"
1.3.6.1.2.1.1.4 = STRING: "888.888.1234"
1.3.6.1.2.1.1.6 174 days, 6:22:10.00
Upvotes: 1
Views: 171
Reputation: 123500
When you don't quote your variable, the shell will put them all on the same line, so your command should work:
OUTPUT=`snmpget 172.0.0.1 -c public -v 1 1.3.6.1.2.1.1.2 1.3.6.1.2.1.1.4 1.3.6.1.2.1.1.6`
echo "Multiple lines: $OUTPUT"
echo Single line: $OUTPUT
You can also do this without the variable, by replacing line feeds with spaces:
snmpget 172.0.0.1 -c public -v 1 1.3.6.1.2.1.1.2 ... | tr '\n' ' '
Upvotes: 3
Reputation: 1696
Using inline field separator set to '" '
IFS='" ' read -ra $OUTPUT <<< "$IN"
for i in "${OUTPUT[@]}"; do
echo $i
done
Upvotes: 0