# About script

**URL:** <https://community.f5.com/t/about-script/71106>\
**Category:** Technical Forums\
**Tags:** application-delivery\
**Created:** [December 1, 2022, 4:32pm UTC](https://community.f5.com/t/about-script/71106 "2022-12-01T16:32:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michaelyang](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/michaelyang/32/22761_2.png) [@Michaelyang](https://community.f5.com/u/Michaelyang)\
**Post date:** [December 1, 2022, 4:32pm UTC](https://community.f5.com/t/about-script/71106/1 "2022-12-01T16:32:26Z")

</div>

Hello,

I want to make a script that sends alerts to /var/log/ltm every minute when the pool is not up.  
Here&nbsp;is the script I designed:

```tcl
modify script pool_script {
    app-service none
    definition {
        set errorcode [catch {exec tmsh show ltm pool | grep Ltm | awk {{ print $(NF-2) }}} result]
        set result [split $result "\n"]

        tmsh::log_dest file
        tmsh::log_level debug

        foreach i $result {
            set pool "[lindex $i 1]"
            if { [tmsh::show ltm pool] contains "Availability : available" } then {

            } else {
                tmsh::log debug "F5 Pool:${pool} Status -> Not available."
            }
        }
    }
    description none
    events none
}

```

I thought it worked, but then I realized that the log only appears when the first pool doesn’t start as it should.  
Please tell me how to change my script…

Any help is appreciate.

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [December 1, 2022, 4:53pm UTC](https://community.f5.com/t/about-script/71106/2 "2022-12-01T16:53:48Z")

</div>

Hi Michaelyang,

on a quick view: You are not passing $pool to the “tmsh::show ltm virtual” command…

Cheers, Kai

---

<div class="post-metadata">

**Author:** ![Michaelyang](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/michaelyang/32/22761_2.png) [@Michaelyang](https://community.f5.com/u/Michaelyang)\
**Post date:** [December 1, 2022, 4:58pm UTC](https://community.f5.com/t/about-script/71106/3 "2022-12-01T16:58:20Z")

</div>

Hi Kai\_Wike,

Sorry, I sent the wrong one  
I’ve updated it…

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [December 1, 2022, 5:08pm UTC](https://community.f5.com/t/about-script/71106/4 "2022-12-01T17:08:10Z")

</div>

As i said… you are not passing the $pool variable into the&nbsp;the “tmsh::show ltm virtual” command. In this case you check if a single pool of all your pools is available. It should be&nbsp;“tmsh::show ltm virtual $pool”

Beside of this the [exec] part can be avoided… Give me a sec to give you a quick coding how to access and enumerate LTM configurations within TMSH scripts…

Cheers, Kai

---

<div class="post-metadata">

**Author:** ![Michaelyang](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/michaelyang/32/22761_2.png) [@Michaelyang](https://community.f5.com/u/Michaelyang)\
**Post date:** [December 1, 2022, 5:09pm UTC](https://community.f5.com/t/about-script/71106/5 "2022-12-01T17:09:58Z")

</div>

Hi Kai\_Wike,

Sorry, I sent the wrong one  
I’ve updated it again…

Thank you

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [December 1, 2022, 5:11pm UTC](https://community.f5.com/t/about-script/71106/6 "2022-12-01T17:11:59Z")

</div>

Hi MIchaelyang,

check the iCall script below to get a picture how to LTM configs could be enumerated with foreach loops.&nbsp; No need to [exec] native BASH commands… 😉

```tcl
sys icall handler periodic check_pool_state {
    interval 120
    script check_pool_state
}
sys icall script check_pool_state {
   app-service none
   definition {
		tmsh::log_dest file
		tmsh::log_level debug
		foreach temp(pool_config) [tmsh::get_config /ltm pool] {
			set temp(pool_name) [tmsh::get_name $temp(pool_config)]
			if { [tmsh::show /ltm pool $temp(pool_name)] contains "Availability : available" } then {
				# Everything is fine... 	
			} else {
				tmsh::log debug "Pool Check: $temp(pool_name) is unhealthy"
			}
		}
   }
   description none
   events none
}

```

Cheers, Kai

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [December 1, 2022, 5:15pm UTC](https://community.f5.com/t/about-script/71106/7 "2022-12-01T17:15:27Z")

</div>

Still the same problem. Check the script I’ve just posted. During the foreach loop it passes the currently processed $temp(pool\_name) to the [tmsh::show] command, so that you analyse the state of the just processed pool. If you dont pass the pool name to the show command, then you would analyse all pools at the same time.

Cheers, Kai

---

<div class="post-metadata">

**Author:** ![Michaelyang](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/michaelyang/32/22761_2.png) [@Michaelyang](https://community.f5.com/u/Michaelyang)\
**Post date:** [December 1, 2022, 5:39pm UTC](https://community.f5.com/t/about-script/71106/8 "2022-12-01T17:39:28Z")

</div>

Hi Kai\_Wike,

Thanks for your help.

I’ll look into it..

Thanks

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [December 1, 2022, 5:41pm UTC](https://community.f5.com/t/about-script/71106/9 "2022-12-01T17:41:13Z")

</div>

You are welcome.

I pretty much like to see you enjoying iCall. You truly deserve Kudos for your creativity 😉

Cheers, Kai
