dropbear启动脚本

#!/bin/bash
# chkconfig: 2345 75 50 默认级别 启动级别 关闭级别
# description: dropbear ssh daemon
dsskey=/etc/dropbear/dropbear_dss_host_key
rsakey=/etc/dropbear/dropbear_rsa_host_key
pidfile=/var/run/dropbear.pid
lockfile=/var/lock/subsys/dropbear
dropbearkey=/usr/local/bin/dropbearkey
dropbear=/usr/local/sbin/dropbear

[ -r /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions
[ -f /etc/sysconfig/dropbear ] && . /etc/sysconfig/dropbear
keysize=${keysize:-2048}
port=${port:-22}

gendsskey() {
[ -d /etc/dropbear ] || mkdir /etc/dropbear
echo -n "Starting generate the dss key:"
$dropbearkey -t dss -f $dsskey &>/dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
success
echo
return 0
else
failure
echo
return 1
fi
}

start () {
[ -e $deskey ] || gendsskey
[ -e Srsakey ] || genrsakey
if [ -e $lockfile ] ; then
echo -n "dropbear daemon is already running"
success
echo
exit 0
fi
echo -n "Starting dropbear: "
daemon --pidfile="$pidfile" $dropbear -p $port -d $dsskey -r $rsakey
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
touch $lockfile
return 0
else
rm -f $lockfile $pidfile
return 1
fi
}

stop () {
if [ ! -e $lockfile ] ; then
echo -n "bear service is stopped:"
success
exit 1
fi
echo -n "Stopping dropbear daemon:"
killproc dropbear
RETVAL=$?
echo

if [ $RETVAL -eq 0 ] ; then
rm -f $lockfile $pidfile
return 0
else
return 1
fi
}
status () {
if [ -e $lockfile ] ; then
echo "dropbear is running."
else
echo "dropbear is stopped"
fi
}
usage () {
echo "Usage:dropbear {start|stop|restart|status|gendsskey|genrsakey}"
}

case $1 in
start)
start ;;
stop)
stop ;;
restart)
stop
start ;;
status)
status ;;
gendsskey)
gendsskey ;;
genrsakey)
genrsakey ;;
*)
usage ;;
esac

posted @ 2019-08-01 16:24  骑驴玩脚本  阅读(1338)  评论(0编辑  收藏  举报