LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/)
-   -   how to redirect the cron output to screen (https://www.linuxquestions.org/questions/ubuntu-63/how-to-redirect-the-cron-output-to-screen-838200/)

pingao777 10-15-2010 03:19 AM

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

dwlegg 10-15-2010 03:39 AM

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.

rigor 10-15-2010 04:02 AM

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.

pingao777 10-15-2010 08:21 AM

Quote:

Originally Posted by kakaka (Post 4128185)
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.

rigor 10-15-2010 11:43 AM

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.

pingao777 10-16-2010 09:24 AM

Thank you for your help!


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