Hi i would like to know how to use cron jobs to create three login messages.
I am running centOS 5.7 (bash shell), What i am trying to do is to set it up so that each week on tuesday if users log in between 5PM and 6PM,a message would be displayed. that's about it.
Thank you much. |
If I assert it's command line logins you're targeting, then when you look at 'man crontab; man 5 crontab; man issue; man motd' do you think you can come up with (pseudo) code for this or otherwise show you've got any idea for trying?
|
Hi, from crontab -e the code that i used is:
00 17,18 * * 2 echo "Welcome and please remember we are working on math today." > /etc/motd 00 18,19 * * 2 echo "Welcome i hope you are ready for some math today." > /etc/motd 00 19,20 * * 2 echo "Welcome i know its geting late, but never to late for math right?" > /etc/motd and what i'm trying to do here is echo the message and redirect and overwrite the /etc/motd file. But when i try it out it does not work because i am doing someting wrong and it will not redirect. Please if you need more info please let me know thanks much. |
Another way to handle this is to use a script file to post the message in your motd file. It could be 3 simple executable scripts:
math #!/bin/sh #**************************************************************************# echo "Welcome and please remember we are working on math today." echo "Welcome and please remember we are working on math today." > /etc/motd #**************************************************************************# exit math1 #!/bin/sh #**************************************************************************# echo "Welcome i hope you are ready for some math today." echo "Welcome i hope you are ready for some math today." > /etc/motd #**************************************************************************# exit math2 #!/bin/sh #**************************************************************************# echo "Welcome i know its geting late, but never to late for math right?" echo "Welcome i know its geting late, but never to late for math right?" > /etc/motd #**************************************************************************# exit Schedule these 3 script as you previously have. 00 17,18 * * 2 /bin/bash /path_to_script/math 00 18,19 * * 2 /bin/bash /path_to_script/math1 00 19,20 * * 2 /bin/bash /path_to_script/math2 |
Quote:
Quote:
Code:
#!/bin/bash |
Part of the problem could be your cron scheduling. You're printing message 1 at both 17 and 18 UT, message 2 at both 18 and 19 UT, and message 3 at both 19 and 20 UT. This means that message 1 AND message 2 will both be trying to write to motd at 18 UT, and message 2 AND message 3 will both be trying to write to motd at 19 UT. This could lead to some interesting behavior.
|
Thank you all.
The last post: Part of the problem could be your cron scheduling. You're printing message 1 at both 17 and 18 UT, message 2 at both 18 and 19 UT, and message 3 at both 19 and 20 UT. This means that message 1 AND message 2 will both be trying to write to motd at 18 UT, and message 2 AND message 3 will both be trying to write to motd at 19 UT. This could lead to some interesting behavior. is where i was going wrong so i fixed it. And yes Tuesday is 2 Thank you all very much |
All times are GMT -5. The time now is 04:33 PM. |