LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 08: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 08:47 AM.
 
Old 01-20-2018, 09:05 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 11,512

Rep: Reputation: 3457Reputation: 3457Reputation: 3457Reputation: 3457Reputation: 3457Reputation: 3457Reputation: 3457Reputation: 3457Reputation: 3457Reputation: 3457Reputation: 3457
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 09:06 AM.
 
1 members found this post helpful.
Old 01-20-2018, 09: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:43 AM
[SOLVED] Getting some errors while executing a shell script. Satyaveer Arya Programming 2 07-13-2012 12:21 AM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 10:12 PM
difference between cron and command line environment? shell script errors danpaluska Linux - Newbie 3 02-18-2010 05:38 PM

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

All times are GMT -5. The time now is 07:01 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration