fi
# Check what options awk supports
- if [ ! -z `ssh $HOSTNAME "echo | awk -W interactive '{print 1}' 2>&1 >/dev/null"` ]; then
+ if [ "`ssh $HOSTNAME \"echo | awk -W interactive '{print 1}' 2>&1 1>/dev/null\"`" != "" ]; then
awkopt=""
else
awkopt="-W interactive"
fi
ssh -q $HOSTNAME <<EOF
- vmstat $vmopt $DELAY | awk $awkopt -v host=$HOSTNAME 'BEGIN {
+ nohup stdbuf -o0 vmstat $vmopt $DELAY | awk $awkopt -v host=$HOSTNAME 'BEGIN {
OFS="|"
}
/us/ {
if(idcol != 0)
print ts,host,"CPU-ID",\$idcol
close("date '+%s'")
- }' >> $OUTPATH &
+ }' >> $OUTPATH 2>/home/bdsm/err.log &
EOF
ssh -q $HOSTNAME "ps aux | \
grep bdsm | \
# Bash Daemon for System Monitoring
#
# TODO:
-# 1) Fully shakeout configure
+# 1) Finish configure options
# 2) Finish Deploy
# ) Plugins:
# 3) iostat
start()
{
+ # Start the processor
+ #TODO: Plugin system?
+ cat /home/bdsm/in.fifo > /home/bdsm/bdsm.log &
+ echo $! > /home/bdsm/.processor.pid
+
i=0
while [ $i -lt ${#hosts[@]} ]; do
type=`echo ${hosts[$i]} | cut -d':' -f1`
info "Starting $type monitors on $host..."
functions=`cat /home/bdsm/.bdsm.conf.tmp | grep "$type:$host" | sed 's/.*{\(.*\)}.*/\1/'`
+ ssh $host "cat /home/bdsm/out.fifo" > /home/bdsm/in.fifo &
+ echo $! > /home/bdsm/pids/$host.in
+
+
j=0
echo $functions | tr ';' '\n' | sed 's/[(),]/ /g' | while read line; do
command=`echo $line | cut -d' ' -f1`
error "Could not find plugin for $command on $type:$host!"
fi
done
-
- ssh $host "cat /home/bdsm/out.fifo" > /home/bdsm/in.fifo &
- echo $! > /home/bdsm/pids/$host.in
-
+
i=`expr $i + 1`
done
}
read host
if [ `confirm "Confirm creation of $type:$host?"` -eq 0 ]; then
- echo "$host{}" >> /home/bdsm/.bdsm.conf.tmp
+ echo "$type:$host{}" >> /home/bdsm/.bdsm.conf.tmp
else
host=""
fi
header "Configuring $service"
if [ `confirm "Disable $service?"` -eq 0 ]; then
- # TODO
- # This may need fixed
- # TODO
cat /home/bdsm/.bdsm.conf.tmp | \
sed 's/\(.*:$host{.*\)$service;\(.*\)/\1\2/g' \
> /home/bdsm/.bdsm.conf.tmp2
done
newservice=`echo $newservice | sed 's/,$/)/g'`
fi
-
+
+set -x
# TODO
# Validate removal/replacement of old service
# TODO
mv /home/bdsm/.bdsm.conf.tmp2 /home/bdsm/.bdsm.conf.tmp
# Reload the hosts list
hosts=$(cat /home/bdsm/.bdsm.conf.tmp | cut -d'{' -f1)
+set +x
done
# Convert config back to a more readable format
host=`echo ${hosts[$i]} | cut -d':' -f2-`
info "Deploying on $host..."
- ssh -q bdsm@$host
+ ssh -q -o PreferredAuthentications=publickey bdsm@$host "echo > /dev/null"
ret=$?
- if [ ! $ret ]; then
- info "Passwordless SSH not configured. Creating bdsm user as root..."
- ssh root@$host "useradd --home-dir /home/bdsm bdsm"
+ if [ $ret -ne 0 ]; then
+ info "Passwordless SSH not configured. Login as root to configure:"
+ cat /home/bdsm/.ssh/id_rsa.pub | ssh -q root@$host "cat >> /tmp/bdsmid; useradd --home-dir /home/bdsm bdsm; mkdir -p /home/bdsm/.ssh/; cat /tmp/bdsmid >> /home/bdsm/.ssh/authorized_keys"
- info "Logging in as bdsm user to transfer SSH key..."
- cat /home/bdsm/.ssh/id_rsa.pub | ssh bdsm@$host 'cat >> ~/.ssh/authorized_keys'
+ #info "Logging in as bdsm user to transfer SSH key..."
+ #cat /home/bdsm/.ssh/id_rsa.pub | ssh bdsm@$host 'cat >> ~/.ssh/authorized_keys'
fi
- ssh bdsm@$host "mkfifo /home/bdsm/out.fifo"
+ ssh -q bdsm@$host "mkfifo /home/bdsm/out.fifo"
+ i=`expr $i + 1`
done
+
+ mkfifo /home/bdsm/in.fifo
+ mkdir /home/bdsm/pids
}
# SCRIPT START
> /home/bdsm/.bdsm.conf.tmp
# Get a list of configured hosts
-hosts=$(cat /home/bdsm/.bdsm.conf.tmp | cut -d'{' -f1)
+hosts=($(cat /home/bdsm/.bdsm.conf.tmp | cut -d'{' -f1))
if [ -z $1 ]; then
help
deploy
else
help
-fi
\ No newline at end of file
+fi