LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Run cron job in terminal emulator window (http://www.linuxquestions.org/questions/linux-software-2/run-cron-job-in-terminal-emulator-window-946425/)

Beaverfriend 05-23-2012 04:01 AM

Run cron job in terminal emulator window
 
Hi,

I have a backup script that I would like to open up a new terminal emulator window every day it runs from cron, so I can follow what's happening.

How can this be achieved?

Looking forward to your answer! Thanks!

jhwilliams 05-23-2012 04:10 AM

The better solution is to have your cron job write to a log file.

Then, you can run
Code:

tail -f /log/file
But, what you propose is likely possible. You'd need to "wrap" your existing script with code like this, below. This gets a handle to the GUI session, and then launches gnome-terminal, running your command.

Code:

#!/bin/bash
# This is your new cron script.
#

user="your-username-here"

dbus_address=$(cat /home/$user/.dbus/session-bus/*-0 | \
                grep -v '\#' | \
                grep BUS_ADDRESS | \
                cut -d '=' -f 2-)

# Here, replace /path/to/script.sh with whatever the old cron script was.
DBUS_SESSION_BUS_ADDRESS=$dbus_address \
    su $user -c gnome-terminal -e "sudo /path/to/script.sh"

Anyway, there are still a lot of issues with this. Please don't try to do it; you'd be better off looking at Nagios or some other monitoring software.

lithos 05-23-2012 05:23 AM

Hi Beaverfriend

Maybe you could try running your script in screen
like:
- this
- or maybe here

good luck

Beaverfriend 05-24-2012 05:06 AM

Quote:

Originally Posted by jhwilliams (Post 4685415)
The better solution is to have your cron job write to a log file.

You're right, that would be the better solution! Thanks all for tips everyone!


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