[home]

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/bash

declare -A MAC_ADDR

MAC_ADDR[myhost01]=00:19:d1:b5:a2:aa
MAC_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... ;/

Comments

  1. omega replica says:
    September 4, 2010 @ 08:21 — Reply

    good storzblog luck

[home]

Leave a Comment

Line and paragraph breaks automatic, HTML allowed: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <code> <em> <i> <strike> <strong>



Put the word storzblog somewhere in your comment, this is my spam-protection. :)

[home]