Forum Discussion

ramann_75062's avatar
ramann_75062
Icon for Nimbostratus rankNimbostratus
Oct 29, 2009

Export variables in external monitor script

Hi@all,

 

 

 

is there a way to export variables in a external bash monitor script and use then in the next run of the script?

 

 

I tried it via "export $BLA" but this does not work.

 

 

I tried also an "echo $BLA >> /var/log/filename", but then I have the problem, that the output is most time not written to the file - is there an limitation?

 

 

The goal of my script is to set an counter that not every time when the script detects that a pool member is down, a mail is send.

 

 

OS: BIG-IP 9.4.6 Build 401.0 Final

 

 

 

Thanks

 

Bjoern

 

 

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi Bjoern,

     

     

    Try searching online for "bash export environment variable" and you'll find plenty of references to the fact that a script can only modify the state of itself and its child processes--not the process that called the script:

     

     

    http://www.linuxquestions.org/questions/linux-newbie-8/how-to-export-environment-variable-from-a-bash-script-344057/

     

     

    I'm surprised to hear that you're not able to redirect output from the script to a file though. This should work. Many of the Codeshare external monitor scripts use this type of functionality to create a lock file and ensure only one instance of the script is running per pool member instance at a time.

     

     

    That said, couldn't you write to /var/log/ltm and then use syslog to handle the emails?

     

     

    Aaron
  • Hi Aron,

     

     

    i made some more tests - the problem with output into an file is only happens when the output command is at the end of the script - when its in the middle, its no problem.

     

     

    Thanks for the idea with the child script, but it is not working for our goal. The problem is when i have one script and 10 nodes to check every 5 seconds, then when one or more nodes are down, the system send a lot of mails :-) - to prevent this, my idea was to handle it via a variable counter, of course, I can use a counter via an filesystem object, but i am not sure about the performance.

     

     

    Using syslog is an good idea! Does F5 have some sample scripts/configs about that? :-)

     

     

    THanks

     

    Bjoern

     

     

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    I think the issue is that after you echo something to standard out, the script is stopped and the pool member is marked up. So make sure to include any code you need to have run on every execution before any standard output is sent.

     

     

    Here's an article that might help you implement email throttling:

     

    http://www.campin.net/newlogcheck.html ->

     

    http://www.campin.net/bash-mail-alert

     

     

    Aaron