Wakeup script using BASH associative arrays
September 10, 2009
Now that we have associative arrays in BASH 4, we can do cool stuff like:
#!/bin/bashdeclare -A MAC_ADDRMAC_ADDR[myhost01]=00:19:d1:b5:a2:aaMAC_ADDR[somehost02]=00:30:18:af:f3:47#------------------------------------echo_known_hostnames() { echo "Known hosts: ${!MAC_ADDR[@]}"}[ $# -eq 0 ] && { echo "Usage: $(basename $0) hostname" echo_known_hostnames exit 0}HOST="$1"[ -z "$(grep $HOST <(echo ${MAC_ADDR[@]}))" ] || { echo_known_hostnames exit 1}TARGET=${MAC_ADDR[$HOST]}[ -n "$TARGET" ] && { /usr/sbin/etherwake $TARGET}# had to set suid-bit on etherwake# so that users can use this... ;/
omega replica says:
September 4, 2010 @ 08:21 — Reply
good storzblog luck