need help with shell programing script

  1. The problem statement, all variables and given/known data:
    Write a Shell script to automatically check that a specified user is logged in to the computer.
    The program should allow the person running the script to specify the name of the user to be checked, the frequency in seconds at which the script should check. If a checking frequency is not specified, it should default to 60 seconds
    The script should check for the specified user and if found should output a message with a �beep� or �bell� sound to the screen stating that the user is logged in. It should also output a message to a log file stating that the user is logged in and specifying the date and time.
    If the user is not logged in the script should output a message without any �beep� sound to the screen stating that the user is not logged in.
    The script should allow a person running the script to specify the user name on the command line and optionally, a check frequency in seconds and a third argument �q� �q� . If �q� is present as a third argument, The script should omit any output to the screen or �beep� sound but should log to a log file the message stating that the user is logged in and giving the time.

  2. Relevant commands, code, scripts, algorithms:
    The command to run the script would be as follows:
    checklogin username 30 q where �checklogin� is the script name, �username� is the name of the user, �30� is the optional frequency to check in seconds, and �q� is the optional argument to suppress screen output.
    The script should check that the number of arguments supplied is between 1 and 3 and if it is not, should terminate with an error message showing the correct syntax for the command.

  3. The attempts at a solution (include all code and scripts):
    who | grep $username
    echo -e "\a"

  4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    Blanchardstown institute of technology, dublin, ireland, Ronan O'Mallay, dt228

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Where exactly are you stuck? Because we won't write a script for you, only help you through difficulties.

i just need help on how to put the commands together into a script.

---------- Post updated at 01:19 PM ---------- Previous update was at 04:58 AM ----------

iv been working on it and this is what i have so far.

default= 60
if 
who | grep $username
then
  echo -e "the user has logged on \a"
  echo "the user logged in at : `date` ">> LOGFILE
  echo $?
fi

I need to know how to put the username into the logfile.

echo "$username logged in at : `date` ">> LOGFILE

With double quotes the shell will look inside and replace variables. I assume you set username somewhere in code that you do not show.

iv been working and iv got this far:

for i in `seq 1 05`
do
echo"enter username"
read username
if
who | grep $username
then
echo -e "the user is logged on \a"
echo -e "\007"
echo "$username logged in at : `date`">>LOGFILE
else
echo "the user is not logged on"
echo $?
fi
done default =60

Does anybody know how to set the frequency that is stated above in the brief.

The exact same way you read the username will work to read something else.

Then check if they left it blank if [ -z "$delay" ] and, if so, set it to 60.