[SOLVED] how to pass variables to bash script?

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
jabarlee
Posts: 5
Joined: Sun Jan 16, 2005 11:19 am

[SOLVED] how to pass variables to bash script?

Post by jabarlee »

I try to create my first script as a data input method, but I have a problem.

Code: Select all

#!/bin/bash
iwlist $1 peers | grep $2 | awk -F\= '{print $3}' | awk '{print $1}'
the "iwlist <wlan> peers" command displays the (wirelessly) connected peers, along with their signal strength
$1 : the interface I want to monitor
$2 : the mac address of the peer


when I execute the script myself, everything is ok:

Code: Select all

caribou:/usr/share/cacti/scripts# ./test.sh ath1 00:40:96:A1:56:19
-64
But in the cacti log it seems there is an error:

Code: Select all

10/27/2005 12:45:06 PM - CMDPHP: Poller[0] Host[2] DS[156] WARNING: Result from CMD not valid.  Partial Result:
10/27/2005 12:45:06 PM - CMDPHP: Poller[0] Host[2] DS[156] CMD: sh /usr/share/cacti/scripts/test.sh ath1 00:40:96:A1:56:19, output: U
Any ideas what is wrong?

*** Sorry, I've posted in the wrong section, plz move me :-)
caught in e w3b ...
jabarlee
Posts: 5
Joined: Sun Jan 16, 2005 11:19 am

Post by jabarlee »

I've corrected the above post with some more specific details of the problem
caught in e w3b ...
jabarlee
Posts: 5
Joined: Sun Jan 16, 2005 11:19 am

Post by jabarlee »

a friend advised me that the problem was probably the "newline" (\n) of the output of the script, so I changed it to:

Code: Select all

!/bin/bash
iwlist $1 peers | grep $2 | awk -F\= '{print $3}' | awk '{printf $1}'
result:
caribou:/usr/share/cacti/scripts# ./test.sh ath1 00:40:96:A1:56:19
-63caribou:/usr/share/cacti/scripts#
but still no luck ...
caught in e w3b ...
User avatar
mojiro
Cacti User
Posts: 121
Joined: Sun Jul 24, 2005 12:20 pm
Location: Ireland, Dublin

Post by mojiro »

jabarlee wrote:a friend advised me that the problem was probably the "newline" (\n) of the output of the script, so I changed it to:

Code: Select all

!/bin/bash
iwlist $1 peers | grep $2 | awk -F\= '{print $3}' | awk '{printf $1}'
result:
caribou:/usr/share/cacti/scripts# ./test.sh ath1 00:40:96:A1:56:19
-63caribou:/usr/share/cacti/scripts#
but still no luck ...
(edo epitrepontai ta greeklish arage ?) :o
anyway jabaman, come to our channel to solve your problem
User avatar
fmendez75
Posts: 7
Joined: Tue Dec 05, 2006 1:25 pm
Location: NYC, NY

check your web's access right.

Post by fmendez75 »

I had a similar problem once with a script and when I checked I didn't the web server didn't have enough access to execute the script.
User avatar
Alice
Cacti User
Posts: 111
Joined: Tue Oct 28, 2003 4:54 pm
Location: Bucharest, RO.

Post by Alice »

a: try to write the full path in the file:
!/bin/bash
/xxx/bin/iwlist $1 peers | grep $2 | awk -F\= '{print $3}' | awk '{printf $1}'

b: MAYBE cacti doesn't like negative numbers:
!/bin/bash
/xxx/bin/iwlist $1 peers | grep $2 | awk -F\= '{print $3}' | awk '{printf $1}' |cut -d '-' -f 2-

see if that helps.
[url=http://www.x-graphs.com/]http://www.x-graphs.com[/url] [color=red]X[/color]-[color=blue]graphs[/color] :: All kind of graphs
slander
Posts: 32
Joined: Thu Mar 16, 2006 12:01 pm

Post by slander »

result:
caribou:/usr/share/cacti/scripts# ./test.sh ath1 00:40:96:A1:56:19
-63caribou:/usr/share/cacti/scripts#
but still no luck ...[/quote]


You might try running this from the command line exactly as cacti does; IE logged in as cactiuser, start NOT in the scripts directory, and use the full command line "/usr/share/cacti/scripts/test.sh ath1 00:40:96:A1:56:19"

possibilities, cactiuser doesn't have execute rights, iwlist isn't in path or is not executable, awk not in path, etc.
jabarlee
Posts: 5
Joined: Sun Jan 16, 2005 11:19 am

Post by jabarlee »

After a very long time that I decided to look again at my script...

Indeed Slander, it was a permissions problem. I used sudo and did my job nice and easy :-)
caught in e w3b ...
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests