need help with shell programing script

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions need help with shell programing script
# 1  
Old 04-12-2011
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).
# 2  
Old 04-12-2011
Where exactly are you stuck? Because we won't write a script for you, only help you through difficulties.
# 3  
Old 04-13-2011
Tools

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.
Code:
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.

Last edited by Franklin52; 04-13-2011 at 03:46 PM.. Reason: Please use code tags, thank you
# 4  
Old 04-13-2011
Quote:
Originally Posted by operator
I need to know how to put the username into the logfile.
Code:
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.
This User Gave Thanks to Perderabo For This Post:
# 5  
Old 04-14-2011
Bug more progress

iv been working and iv got this far:

Code:
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.

Last edited by pludi; 04-14-2011 at 02:55 PM..
# 6  
Old 04-14-2011
Quote:
Originally Posted by operator
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.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Shell programing to implement SQL package

hi all, i have a table with employee details like his name,addr,DOB etc. i need a shell program which takes one date as input from user and print the employees whose DOB is less than that date. in sql package the select query is written (2 Replies)
Discussion started by: vidyaj
2 Replies

2. Programming

Unicode programing in C

im starting to go a little serious with c, woking in a personal project that will read a xml, which might contain Unicode characters (i know it will on my system, which is set to es_AR.UTF-8) im using mxml, and the documentation says it uses utf8 internally (no worries here). so i need to be... (4 Replies)
Discussion started by: broli
4 Replies

3. Shell Programming and Scripting

Shell Programing with awk Tool

I'm working on a program in with shell programming and it needs to be able to delete the contents of files in the Home directory on certain days of the week.(like tuesday). Can anyone help me with this? Thanks in advance, Taffy. (7 Replies)
Discussion started by: Taffy
7 Replies

4. Shell Programming and Scripting

shell programing...

Hi... i need to write a shell script wich shows the full name and station of every logged user in the system. pls help! (1 Reply)
Discussion started by: relu89
1 Replies

5. Programming

A C++ programing Shell on Win

Hello I need to translade the power of unix command shell (grep, sed, awk, wc, etc..) to windows. In my work every day I administrate 15 unix server ans 18 windows server, and I have the problem the absolutly limitation of windows shell. I´m a system administrator but I know programming. I... (2 Replies)
Discussion started by: dalmus
2 Replies

6. Shell Programming and Scripting

Awk Programing (need help)

plx help to solve these problems?? 1. Create a HERE document which will edit multiple files in the same directory, using the ed editor. I give you 3 original files: file1.c , file2.c , file3.c, download them and change each string "stdio.h" to "STDIO.H" in these files. Note: when execute the... (1 Reply)
Discussion started by: SoCalledEngr
1 Replies

7. Linux

Linux game programing or just shell scripting

Well Acording to my job... Anyhelp plz. I need some basic scripting stuff. (3 Replies)
Discussion started by: Irish Jimmy
3 Replies

8. Shell Programming and Scripting

Editing files in shell programing

Hi folks, In our product installation program we edit xml files by deleting lines and appending new lines instead of them. For example: update_Log4plsql_xml() { machineName=`uname -n` hostIP=`cat /etc/hosts | grep ${machineName} | cut -f1` trap 'clean_up | tee -a $installLog ; exit' 1 2... (0 Replies)
Discussion started by: nir_s
0 Replies

9. Shell Programming and Scripting

mutex in shell programing

A shell in crontab per 5 min write a file B shell in crontab per 6 min read a file how to lock the share file a ;avioid confilict in write and read? Thx : -) (1 Reply)
Discussion started by: zz_xm
1 Replies

10. UNIX Desktop Questions & Answers

Graphics programing

Hi all! I`m new in Unix (Linux) and i whant to ask something! What language should i use for Linux developing.I meen applications an GAME DEVELOPING! Should i use C,TCL ??? Please help me on this ...:( (1 Reply)
Discussion started by: Sebastyan
1 Replies
Login or Register to Ask a Question