#!/bin/sh
# sof - sshd on five.
# runs the sshd server for 5 minutes. If the permitted user
# does not log in within that time sshd is stopped untill Cron
# starts sshd the next time. If a login is made sshd remains
# running. Its purpose is to limit sshd login to specified 
# timeslots.
#
# Install - run the script with cron,  eg- every hour 6am-11pm
# daily. "0 6-23 * * *". See 'man crontab'.
# Assign the ssh client login_name to USER.
# The other values can be changed to any command or length of
# time provided the awk output from ps matches the user value.
#
# This script can be shared and modified as stated in the Gnu Software
# Licence at www.gnu.org and comes with no warranty.
#
# TODO - add user list file so more than one user can log in.
# Release date-  16/09/05
#
# Variables- assign the ssh client login_name
PROG=sshd
USER=ssh_login_name
PERIOD=5m
#
# 
killall $PROG > /dev/null 2>&1 
$PROG
#send self grep of first grep output to null.  
ps ax | grep $PROG > /dev/null 2>&1
sleep $PERIOD 
if [ "`ps ax | grep "$PROG: $USER@" | sed -e 's/@.*//' | awk '{print $6}'`" = "$USER" ]; then
break
else 
killall $PROG 
fi
exit
