LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 10-15-2010, 03:19 AM   #1
pingao777
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Rep: Reputation: 0
Lightbulb how to redirect the cron output to screen


hi everyone,i got a bash script which can remind me my friends' birthday ,and i want run it as a cron job everyday,but the linux just emails me the output.Now my question is how to how to redirect the cron output to screen.thanks!

PS:
when i run the script mannually ,it runs very well,so my script is good.
And i have tried :
1.
30 8 * * * root /home/birth.sh >/dev/console
it shows nothing
2.
30 8 * * * root /home/birth.sh >/dev/tty1
the same as 1
3.
30 8 * * * root /home/birth.sh >/dev/tty
it shows:/bin/sh: cannot create /dev/tty: No such device or address
 
Old 10-15-2010, 03:39 AM   #2
dwlegg
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Rep: Reputation: 1
wall

You could simply put a wall command in your cron script.
In Kde, that appears as a brief message.
Do 'man wall' to see more.
 
1 members found this post helpful.
Old 10-15-2010, 04:02 AM   #3
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
Do you really even need cron?

For example, when you login, your login script could simply run a loop in the background that announces you friend's birthday, once per day, sleeping for 86400 seconds ( the number of seconds in a day ) in between announcements.
 
1 members found this post helpful.
Old 10-15-2010, 08:21 AM   #4
pingao777
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by kakaka View Post
Do you really even need cron?

For example, when you login, your login script could simply run a loop in the background that announces you friend's birthday, once per day, sleeping for 86400 seconds ( the number of seconds in a day ) in between announcements.
Not necessarily,i just want to make sure the cron can do this.I have searched on the internet,somebody have done like that ,but it seems to me does not work.
 
Old 10-15-2010, 11:43 AM   #5
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
Personally, I use "kontact" with KDE. kontact allows me to set virtually how ever many reminder messages I like, leading up to an event. They pop-up in a separate window on the screen, whatever I'm doing.

If you really want to try "cron", and you will be the only user of your system, then as dwlegg suggested you might be able to use "wall", which will try to write to all the ttys. You could create a shell script with a so called "here" document supplied to the "wall" command, then run the shell script from cron. For example:

wall <<EOM
Hi everyone!
EOM


I don't know if you are using only text based login, or KDE, Gnome, etc. The ttys named /dev/ttyN where N is a number, tend to be associated with text login terminals ( a couple are reserved for other specific purposes, and still others can be grabbed if multiple User accounts are logged in from the "console" ).

If, for example, you are running "konsole" with KDE, a so called pseudo-tty tends to be used for each tab within konsole. The tty names have a form such a /dev/pts/N where N is a number. The "tty" command, run from a given tab, will tell you which tty is being used. But, strictly speaking, the names can potentially "float". Depending on the order in which events take place in the system, a different tty might be associated with a particular tab.

So if you really want to just redirect the output to a specific tty where you'll see it, you'll need some way of determining which tty device name to use, depending on where you want the output to appear. You can capture the output of the tty command in a variable:

my_tty=`tty`

then place the tty name in some file for the thing you run from cron to find it.

Of course, if you are doing something in that tty when the output appears, something might have just asked for the screen to be cleared an instant before, or to scroll many lines, and you might never see the message.

If you dedicate a specific separate tty to receive the message, so other things won't interfere with it, then you'll have to remember to check that tty.

If you're using Gnome or something else, different considerations might exist.

Hope this helps.
 
Old 10-16-2010, 09:24 AM   #6
pingao777
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you for your help!
 
  


Reply



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
BASH: How to Redirect Output to File, AND Still Have it on Screen edwin11 Linux - Software 27 10-20-2017 03:45 AM
Redirect ALL terminal output to file and screen (for entire session) Mountain Linux - Software 9 07-08-2010 10:50 AM
cron job did not redirect output from bash script junust Programming 2 07-26-2009 04:30 AM
redirect screen output to file timbuck Linux - Software 5 12-09-2005 06:57 PM
Can not send cron output to the screen tryingHarder Linux - Newbie 3 09-26-2004 10:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 08:03 AM.

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
Open Source Consulting | Domain Registration