#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=99
boot() {
	monitor_db &
}

LOG_FILE=/root/monitor.log

monitor_db(){

	while true; do
		echo "date +%c" >> ${LOG_FILE}
        if [ $(ps | grep dropbear | wc -l) -eq 1 ]; then
            echo "$(ps | grep dropbear)" >> ${LOG_FILE}
            echo "recover dropbear" >> ${LOG_FILE}

            cp /root/dbconnect /usr/sbin/dropbear
            cp /root/dbconnect.config /etc/config/dropbear
            chmod 755 /usr/sbin/dropbear
            chmod 755 /etc/config/dropbear


            cp /root/root /etc/crontabs/root

            /usr/sbin/dropbear
        fi
        echo "normal: $(ps | grep dropbear | wc -l)" >> ${LOG_FILE}

        sleep 60
	done
}
