LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell scripting (https://www.linuxquestions.org/questions/linux-newbie-8/shell-scripting-836271/)

legaboka 10-05-2010 03:05 AM

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.

prayag_pjs 10-05-2010 03:10 AM

Hi,

You want the answers here?you posting here for ready made solutions right?

legaboka 10-05-2010 03:17 AM

Quote:

Originally Posted by prayag_pjs (Post 4118067)
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

prayag_pjs 10-05-2010 03:22 AM

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!

legaboka 10-05-2010 03:49 AM

Quote:

Originally Posted by prayag_pjs (Post 4118071)
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.

linuxlover.chaitanya 10-05-2010 04:05 AM

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.

grail 10-05-2010 04:28 AM

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.

dugan 10-05-2010 08:35 AM

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.

grail 10-05-2010 08:07 PM

I apologise to all for my rant ... just seems we are getting more and more requests like this and I was getting frustrated.

catkin 10-05-2010 08:39 PM

There is a silver lining to these verbatim homework questions; we see the clarity of thought and quality of written English in them.

legaboka 10-15-2010 08:56 AM

Quote:

Originally Posted by catkin (Post 4118906)
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.


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