LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-05-2010, 03:05 AM   #1
legaboka
LQ Newbie
 
Registered: Oct 2010
Posts: 6

Rep: Reputation: 0
Shell scripting


HI there

I am a final year student doign Computer systems engineering and just been introduced to linux. While still strugling to catch up with the commands, I am now given an assignment under shell scripting.

I seriously am strugling to understand this question, can you please assist me.

Here follows the assignment:



Operating Systems III
Some tips
e.g. (test if a file is empty, if it is then display "file is empty" otherwise display "file is not empty")
test –s /home/joe/file1 && echo "file is empty" || echo "file is not empty"
If you need more than one output from the same test, then you can insert the above command in twice
in a shell script e.g.
test –s /home/joe/file1 && echo "file is empty" || echo "file is not empty"
test –s /home/joe/file1 && rm –f /home/joe/file2
The above command will display "file is empty" as well as delete the file called file2.
You can find more examples using the above man or info help.
Another useful command is if. For more information on if type help if. If is similar to the above
command test.
You will need to pipe or redirect data/text where possible using >, >>, < , | etc
There are many other useful commands that can be used to do the test below – the prescribed textbook
might not be sufficient in providing all the commands necessary.
End of tips
Here is the question
Once invoked to run, the shell script should in both cases not show any error messages.
A shell script is created that will do the following
11
1. A shell script must be done to detect if a certain user has logged on or not. The shell script
should have a name that is the same as your surname.
The username of the user must be entered as an argument, once the shell script has been
executed i.e. any user must be detected by the system. If you as a user runs the script and the
other user is logged on then the following should occur:
• Mail should be sent to the user saying:
Hi there, remember to log off before you go home
Cheers
The administrator
• You should get a message on your terminal:
The user ____________ has logged on at:
• The message should continue with the specific terminal and time the user has logged on
at. (35)
2. When the same shell script (as in question 1) is run by you and the specific user has logged off
already, then:
• A message should appear saying:
The user has logged off, and the last recorded time that he has logged on was…….
• It should then indicate a time and date, to which the user was noted to be logged on last
• It should also indicate which terminal the user was logged on to.
• Mail should not be sent to the user that is logged-off. (30)
3. Referring to 1 and 2 above. A log file should be created that records the above user – i.e.
where (which terminal and IP address), when (date and time) and how long he or she has been
logged on (if the user has logged off in the mean time). Data should be appended to this log
file. The file should be called log. The file should be modified whether the shell script in 1.
and 2. has been executed. (15)
4. The shell script must automatically run every minute from Monday to Thursday. On weekends
it must automatically run every third minute.
• A backup file should be also created for the log file in 3 above. This backup file should
be a compressed file of the log file in 3. The backup file should be updated every 2
minutes.
(20)
Should the above shell script/s not function at all then a penalty of 35% will apply, then an attempt will
be made to find the problem and give marks accordingly.




I will appreciate any sort of help, please guys.
 
Old 10-05-2010, 03:10 AM   #2
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: RHEL/Ubuntu/Debian/Fedora/Centos/K3OS
Posts: 1,159
Blog Entries: 4

Rep: Reputation: 149Reputation: 149
Hi,

You want the answers here?you posting here for ready made solutions right?
 
Old 10-05-2010, 03:17 AM   #3
legaboka
LQ Newbie
 
Registered: Oct 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Smile

Quote:
Originally Posted by prayag_pjs View Post
Hi,

You want the answers here?you posting here for ready made solutions right?
YEs please, even if they can be forwaded to my e-mail address: I'll appreciate them.

Thanks

Last edited by legaboka; 10-15-2010 at 08:58 AM.
 
Old 10-05-2010, 03:22 AM   #4
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: RHEL/Ubuntu/Debian/Fedora/Centos/K3OS
Posts: 1,159
Blog Entries: 4

Rep: Reputation: 149Reputation: 149
HI,

Refer this links

http://freeos.com/guides/lsst/
http://tldp.org/LDP/abs/html/
http://www.unix.com/answers-frequent...tutorials.html

Don't expect us to do spoon feeding!

Write the shell scripts and when you face problem in it, lets us know the problem! We will try to rectify those problems!

If you want the solutions urgent then also let us know;we will give the solution for that also!

ALL THE BEST!
 
Old 10-05-2010, 03:49 AM   #5
legaboka
LQ Newbie
 
Registered: Oct 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Red face

Quote:
Originally Posted by prayag_pjs View Post
HI,

Refer this links

http://freeos.com/guides/lsst/
http://tldp.org/LDP/abs/html/
http://www.unix.com/answers-frequent...tutorials.html

Don't expect us to do spoon feeding!

Write the shell scripts and when you face problem in it, lets us know the problem! We will try to rectify those problems!

If you want the solutions urgent then also let us know;we will give the solution for that also!

ALL THE BEST!

Thanks,

I will start practising and will come for consultation. but i am facing a challenge in terms of deadline because its now my tests week and am preparing for other subjects as well. But I will make sure i do something.
 
Old 10-05-2010, 04:05 AM   #6
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Rep: Reputation: Disabled
While you registered on LQ, you were asked to accept the terms and conditions and were shown the rules and one of the rules states that homework questions are not allowed here. So stay by rules. Do something and then when you are stuck at something, come here with issues and you will be generously helped.
 
Old 10-05-2010, 04:28 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I now it has been quite a long time since I went to school / uni but things have certainly changed a lot.
From memory I was only ever given homework or assignments on subject matter that I had been taught. Whereas these days it appears more and more that teachers / lecturers
ask questions way off topic about things that the students have never heard of. I really don't know how you are meant to pass a subject like that.

And on top of all that, they then give you an assignment at the last minute so that it interferes with study??? Shouldn't they really have to give you enough time
to do your assignment and study for tests ... sheesh

Glad I don't have to go back any time soon.
 
Old 10-05-2010, 08:35 AM   #8
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,222

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Grail, another possibility is that the students did not study hard enough earlier, and thus weren't ready when the assignments were given. Considering the work habits you'd associate with someone who would beg strangers to do their homework for them, this is more likely.

To the OP: this is another good Bash tutorial:

http://tldp.org/LDP/Bash-Beginners-Guide/html/

And remove your email address from your posts. You don't want it there.

Last edited by dugan; 10-05-2010 at 08:53 AM.
 
Old 10-05-2010, 08:07 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I apologise to all for my rant ... just seems we are getting more and more requests like this and I was getting frustrated.
 
Old 10-05-2010, 08:39 PM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
There is a silver lining to these verbatim homework questions; we see the clarity of thought and quality of written English in them.
 
Old 10-15-2010, 08:56 AM   #11
legaboka
LQ Newbie
 
Registered: Oct 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
There is a silver lining to these verbatim homework questions; we see the clarity of thought and quality of written English in them.
Hi guys, thanks for your motivation, I have visited the websites you gave to me and have got everything right. I am sorry I frustrated you the last time. I'm very sorry.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-26-2008 11:50 PM
SHELL scripting/ shell functions mayaabboud Linux - Newbie 6 12-26-2007 08:18 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration