Yes - it is the exit status that is relevant.
I was just allowing the exit status returned by pidof to "fall through" to the calling program.
Of course, when I tested it just now, I forgot to add the status call to the case statement and for a few minutes couldn't figure out why it still didn't work!
My working script is
#!/bin/sh
# openssh sshd start script
[ $(id -u) = 0 ] || { echo "must be root" ; exit 1; }
start(){
[ -f /usr/local/etc/ssh/sshd_config ] || { echo "Config file /usr/local/etc/ssh/sshdd_config not found"; exit 1; }
[ -f /usr/local/etc/ssh/ssh_host_rsa_key ] || ssh-keygen -t rsa -N "" -f /usr/local/etc/ssh/ssh_host_rsa_key
[ -f /usr/local/etc/ssh/ssh_host_dsa_key ] || ssh-keygen -t dsa -N "" -f /usr/local/etc/ssh/ssh_host_dsa_key
[ -f /usr/local/etc/ssh/ssh_host_ecdsa_key ] || ssh-keygen -t ecdsa -N "" -f /usr/local/etc/ssh/ssh_host_ecdsa_key
/usr/local/sbin/sshd
}
stop(){
kill $(pidof sshd)
}
restart(){
if pidof sshd >/dev/null; then
stop && start
else
start
fi
}
status(){
pidof sshd >/dev/null
}
keygen(){
ssh-keygen -t rsa -f /usr/local/etc/ssh/ssh_host_rsa_key
ssh-keygen -t dsa -f /usr/local/etc/ssh/ssh_host_dsa_key
}
case $1 in
start) start;;
stop) stop;;
restart) restart;;
status) status;;
keygen) keygen;;
*) echo "Usage $0 {start|stop|restart|keygen}"; exit 1
esac
Speaking of openssh, I note in about line 9 of the above script the line that includes ... ssh-keygen -t ecdsa ... and I wonder, is that generating the elliptical curve keys using the NSA's compromised method or is it something more secure? Is there an encryption expert in the house?