LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-12-2012, 05:07 PM   #1
rahilmaknojia
Member
 
Registered: Dec 2007
Distribution: RHEL6, CentOS6.3
Posts: 188

Rep: Reputation: 32
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
 
Old 09-12-2012, 05:27 PM   #2
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
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?
 
Old 09-12-2012, 06:01 PM   #3
rahilmaknojia
Member
 
Registered: Dec 2007
Distribution: RHEL6, CentOS6.3
Posts: 188

Original Poster
Rep: Reputation: 32
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.
 
Old 09-12-2012, 06:06 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,557

Rep: Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116
Just put it in the user's .bashrc file (or .cshrc, or whatever login file for the shell they use).
 
Old 09-12-2012, 06:35 PM   #5
rahilmaknojia
Member
 
Registered: Dec 2007
Distribution: RHEL6, CentOS6.3
Posts: 188

Original Poster
Rep: Reputation: 32
Yeah, I did that. I was looking for some other ways.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Backing up and/or delete logs with a cron job. NaCo Linux - Server 2 08-01-2009 04:16 AM
how to display cron job activity ufmale Linux - Newbie 1 07-09-2008 06:20 PM
Display welcome message when user logs in thunder44 Linux - General 3 10-16-2007 08:33 AM
keeping logs from a cron job dominant Linux - Newbie 2 03-02-2004 12:37 PM
cron job to print message to all ehpserver Linux - Newbie 1 02-28-2004 10:08 PM

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

All times are GMT -5. The time now is 06:18 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration