UbuntuThis forum is for the discussion of Ubuntu Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.