LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-26-2014, 04:30 AM   #1
zamykiller
LQ Newbie
 
Registered: Mar 2014
Posts: 9

Rep: Reputation: Disabled
problem with integer


Hi,

I want to make a script with SNMP.
But when i do the SNMP get, the value isn't a integer.

I don't know how to fix this. I made a simple script for testing. But i can't fix this.

Quote:
#!/bin/bash
# declare integers
NUM1=1
NUM2=2
waarde= "` snmpget -v 1 -c public 172.16.60.25 .1.3.6.1.4.1.19865.1.2.3.5.0 | awk '{print $4}'`"
echo "waarde = $waarde"

if [ $waarde -eq $NUM1 ]; then
echo "Both Values are equal"
echo "waarde = $waarde"
else
echo "Values are NOT equal"
echo "waarde = $waarde"
fi
thanks and have a nice day
 
Old 03-26-2014, 04:41 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,110

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
in awk you can force to set it to integer by:
awk '{print ($4 + 0)}'
also use " in this line
if [ "$waarde" -eq "$NUM1" ]; then
 
Old 03-26-2014, 04:54 AM   #3
zamykiller
LQ Newbie
 
Registered: Mar 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thans for the fast response.

Your solutions didn't work.

Quote:
in awk you can force to set it to integer by:
awk '{print ($4 + 0)}'
This gives still the same problem.

Quote:
also use " in this line
if [ "$waarde" -eq "$NUM1" ]; then
This is for strings, the problem is, this is a test script, in the real script I want to work with ">"
 
Old 03-26-2014, 05:12 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
If we are talking integers, why not just use an arithmetic test:
Code:
if (( waarde == NUM1 )); then
I would also remove the quotes from the assignment to waarde as I presume you are returning a single digit each time.

This would supposedly make the change to awk not require either (not tested)
 
Old 03-26-2014, 05:30 AM   #5
zamykiller
LQ Newbie
 
Registered: Mar 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
thanks for your replay.

Your solution worked for looking it was equal. But now I want to look or it's bigger than(>).

For the moment it looks like this
Quote:
#!/bin/bash
# declare integers
NUM1=1
NUM2=2
waarde= snmpget -v 1 -c public 172.16.60.25 .1.3.6.1.4.1.19865.1.2.3.5.0 | awk '{print $4}'
echo "waarde = $waarde"

if [ waarde > NUM1 ]; then
echo "Both Values are equal"
echo "waarde = $waarde"
else
echo "Values are NOT equal"
echo "waarde = $waarde"
fi
I get this error : line 8: NUM1: Permission denied
 
Old 03-26-2014, 10:44 AM   #6
zamykiller
LQ Newbie
 
Registered: Mar 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Hi, i fixed it.
this is the script

Quote:
declare -i waarde
declare -i NUM
NUM=700
waarde=$( snmpget -v 1 -c public 172.16.60.25 .1.3.6.1.4.1.19865.1.2.3.5.0 | awk '{print $4}')
NUM2=2
if [ $waarde -gt $NUM2 ]; then
snmpset -v 1 -c public 172.16.60.25 .1.3.6.1.4.1.19865.1.2.1.6.0 i 0
else
snmpset -v 1 -c public 172.16.60.25 .1.3.6.1.4.1.19865.1.2.1.6.0 i 1

fi
thanks and have a nice day!
 
Old 03-26-2014, 11:00 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
You my wish to go back and look at what I posted again ... pay close attention to the shape of the brackets and how many there are ... this is important
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script integer value problem [SOLVED] luboiron Programming 3 09-14-2012 06:41 AM
[SOLVED] Integer parsing problem in mono c# Puneet Jindal Programming 5 10-18-2010 01:05 PM
interesting integer type comparison problem figo Programming 2 09-29-2009 11:35 PM
comparison between pointer and integer a problem? debiant Programming 7 08-28-2006 08:57 PM
cast from pointer to integer of different size: what is the problem??? bobo333 Linux - Software 2 08-27-2006 10:59 PM


All times are GMT -5. The time now is 09:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration