Writing a simple test script that looks for ssh, kills if its running and verifies if its still running. If it isn't, move on. My issue, its cause I don't know how, is to verify if ssh is running still. Also, is there a way have this do this on a remote server? I already have the ssh keys working so all I need is to know how to code that part. below is what I have, help is much appreciated!
#!/sh/bin
check_stat=`ps -ef | grep sshd | grep -v grep | awk '{print $2}'`
if [ "${check_stat}X" != "X" ]
then
echo "SSHD is running"
else
echo "SSHD isn't running"
for pid in $check_stat
do
echo "Killing $pid"
kill -9 $pid
done
fi
This script is meant for an application, I'm only using SSHD as an example but you brought up a good point. I'll switch the sshd to ftpd and go from there.
So the new script is:
#!/sh/bin
check_stat=`ps -ef | grep vsftpd | grep -v grep | awk '{print $2}'`
if [ "${check_stat}X" != "X" ]
then
echo "vsftpd is running"
else
echo "vsftpd isn't running"
for pid in $check_stat
do
echo "Killing $pid"
kill -9 $pid
done
fi