Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.