LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Pop up message from cronjob run script (https://www.linuxquestions.org/questions/linux-general-1/pop-up-message-from-cronjob-run-script-851778/)

Markus2010 12-22-2010 04:40 AM

Pop up message from cronjob run script
 
Hi,

I'm working on a bash script that will be run regularly via a cronjob. As there is no easy way for the user
to see if it's running in the background, I'd like a have some kind of pop up window what say's something
like "Process started" and "Process finished" when it's complete.

I’ve read though some similar threads and came across xmessage. It kind of does what I want, with the
exception of:-
  • I’d like the message “Process started” to stay up for the whole process, but it looks like the script
    won’t continue until the xmessage window is closed.
  • I can’t get any xmessages to appear when the script is run from a cronjob. It only appears if I run the script manually from a terminal window. Which is no good for me.

If anyone has any suggestions that would be great and just to add, it's doesn't have to be xmessage, any text box would do.

I'm working with Redhat 4 and 5, if that makes a difference.

Thanks,

Markus

Chuck Norris destroyed the periodic table, because he only recognises the element of surprise.

catkin 12-22-2010 05:05 AM

There are several alternatives to xmessage including zenity and yad. yad is the most fully featured and is actively being developed.

X applications need to know the name of the X display to open in. Most commonly they get it from the $DISPLAY environment variable. That is set for all processes run within an X session but not when run from cron. If there is only one X display running on the system, you can use export DISPLAY='localhost:0.0' in the script (you may also need export LANG=C, I can't remember why :(). If the cron job is not being run by the same user as the X display belongs to, the user needs to give the cron user permission to access their X display using the xauth command.

Regards the script continuing while the message remains on screen, it should (TM) be possible to "background" the message command using &, note its process ID from the value of $! and then kill it when the script has finished and displays the "Process finished" message.

If using yad, you may find the --on-top and --sticky options useful. IDK if they are available in the alternatives.

wpeckham 12-22-2010 06:55 AM

script run from cron
 
Generally cron is used for running scheduled events. It should not require someone be logged into the machine, much less have a 'gui' style desktop running upon which it might open a message window.

Think about this: if 5 people were logged in running 7 desktop sessions, how would your script decide where to display its window?

Not that it cannot be done, but it is a bit like driving screws in with a hammer: you are misusing your tools!


All times are GMT -5. The time now is 12:02 AM.