Saturday, May 26, 2018

Shell script to play Constant sound until user press a button when a new user logs on,Linux Teacher Sourav,Kolkata 09748184075

#!/bin/sh
#
# 27/05/2018
#
export BEEP=/usr/share/sounds/ubuntu/ringtones/Harmonics.ogg
alias beep='paplay $BEEP'
beepsound()
{
while [ 1 ]
do
beep
 read -t 0.25 -N 1 input
    if [[ $input = "q" ]] || [[ $input = "Q" ]]; then
# The following line is for the prompt to appear on a new line.
        echo
        exit

    fi
done
}

echo "New User Login Alert,Press Q to stop the beep"
numusers=`who | wc -l`
while [ true ]
do
currusers=`who | wc -l`
# get current number of users
if [ $currusers -gt $numusers ] ; then
echo "Someone new has logged on!!!!!!!!!!!"
date
who

beepsound
numusers=$currusers
elif [ $currusers -lt $numusers ] ; then
echo "Someone logged off."
date
numusers=$currusers
fi
sleep 1 # sleep 1 second
done



No comments:

Post a Comment