LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cron job to display new message every time user logs in (https://www.linuxquestions.org/questions/linux-newbie-8/cron-job-to-display-new-message-every-time-user-logs-in-4175426945/)

rahilmaknojia 09-12-2012 04:07 PM

Cron job to display new message every time user logs in
 
Hi,

I want to create a cron job or a script that will run every time there is a new mail in the system mailbox.

I created a script with viewmail.sh

#/bin/bash
echo $MAIL

filename viewmail.sh

So I want the above script to run when there is a new message in users mailbox.

Any help will be appreciated.

Thanks

SecretCode 09-12-2012 04:27 PM

cron is the wrong approach for this. cron is designed for jobs running at regular intervals, e.g. every day. It can do every minute, but not efficiently. You want a daemon, a job that runs continuously in the background.

What is your script supposed to do? What is in the $MAIL variable?

rahilmaknojia 09-12-2012 05:01 PM

echo $MAIL is linux executable script that shows weather you have an new mail or not. When you type #echo $MAIL on the prompt, it will print the location if you have a mail.

For example, I have a cron job that will remind a user on Step 24th at 12PM to "Do not forget to pay your taxes" This will be emailed to users mailbox at 12PM on Step 24th. But what if the user is not logged in? Then user will not know if he has a message in his mailbox. So when he types echo $MAIL on the prompt, he will know that he has a massage in the mailbox.

So if I have a cron job or a script that runs on every time user logs in, the user will know that he has a mail in the mailbox.

suicidaleggroll 09-12-2012 05:06 PM

Just put it in the user's .bashrc file (or .cshrc, or whatever login file for the shell they use).

rahilmaknojia 09-12-2012 05:35 PM

Yeah, I did that. I was looking for some other ways.


All times are GMT -5. The time now is 01:39 AM.