LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-20-2018, 07:38 AM   #1
Acnologia
LQ Newbie
 
Registered: Jan 2018
Posts: 19

Rep: Reputation: Disabled
Question Shell script errors


Hello,

I have a script which doesn't work, and I can't get to know why. Can you help me please ?

My script takes MIB values and put them in a tab. I want to take the third value, 10 times, and get an average of it.

My tab returns for example : 6202 0 17384 0

Here is the script :

Code:
#!/bin/bash


MIB=1.3.6.1.2.1.2.2.1.11 


i=0
total=0

while [ $i -le 10 ]
do
	tab=$(snmpwalk -v1 localhost -c public $MIB | cut -d' ' -f 4)
	
	$total=$(($total + ${tab[2]}))
done


echo $(($total / 10))
I might well try to print only ${tab[2]}, but all I have is an empty line, though ${tab[*]} does print the full tab :




Can you help me debug it please ?

Last edited by Acnologia; 01-20-2018 at 07:47 AM.
 
Old 01-20-2018, 08:05 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,092

Rep: Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365
tab=( $(snmpwalk .... ) )
or if that won't work see mapfile and check probably here: https://stackoverflow.com/questions/...-array-in-bash

by the way you can try to use shellcheck to check your script.

Last edited by pan64; 01-20-2018 at 08:06 AM.
 
1 members found this post helpful.
Old 01-20-2018, 08:38 AM   #3
Acnologia
LQ Newbie
 
Registered: Jan 2018
Posts: 19

Original Poster
Rep: Reputation: Disabled
Indeed it worked. It was all about brackets. Thank you !
And thanks for shellcheck !
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Print stdout and stderr to screen + log file and catch any errors in shell script idaham Linux - General 3 03-28-2013 06:43 AM
[SOLVED] Getting some errors while executing a shell script. Satyaveer Arya Programming 2 07-12-2012 11:21 PM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
difference between cron and command line environment? shell script errors danpaluska Linux - Newbie 3 02-18-2010 04:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration