Hello, I am (trying) to write a script that will check to see how many users are logged on to my machine, and if that number is more than 60 I need to kill off all the oldest sessions that are over 60. So far I have been able to check how many users are on and now I am at the part where I have to actually kill them off. I have chosen to write the idle times for all the logged on users into a file, but I need to add leading zeroes to them in order to properly sort them. How do I do this? the file is /tmp/uidle. This is my code so far:
numusers=$(who -q | grep Total | tr -s " " | cut -d" " -f3)
echo Total number of users: ${numusers}
if test $numusers -gt 60; then
diff=$(expr $numusers - 60)
echo "There are $diff too many users, killing the $diff oldest users..."
who -u | sort -k4.2,6 | grep bhb | tr -s " " | cut -d" " -f5 >> /tmp/uidle
else
echo "There are less than 60 users. Exiting"
fi
exit 1
Thanks