Skip to content

Instantly share code, notes, and snippets.

@fujiwara
Created June 11, 2014 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fujiwara/68dd604a362243c57d08 to your computer and use it in GitHub Desktop.
Save fujiwara/68dd604a362243c57d08 to your computer and use it in GitHub Desktop.
$ zabbix_get_eval.sh system.uname agent.version '[[ $1 =~ "foo" || $2 =~ ^1\.8 ]]'
#!/bin/bash
VALUES=()
# 最後の引数を除いた引数をループして zabbix_get した値を配列に入れる
for KEY in "${@:0:($#)}"
do
V=`zabbix_get -k "${KEY}"`
VALUES=("${VALUES[@]}" "${V}")
done
# 最後の引数は評価式
EXPR="${!#}"
# 評価式に値を渡して評価
bash -c "${EXPR}" -- "${VALUES[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment