Linux:在前台运行cron作业

时间:2023-01-31 01:08:38

In Linux, is there a way to run a cron job in the foreground (or interactive mode)? (I have a program that runs periodically to accept user input and do some processing. So I want to schedule it as a cron job that can run in the foreground).

在Linux中,有没有办法在前台(或交互模式)中运行cron作业? (我有一个程序定期运行以接受用户输入并进行一些处理。所以我想将它安排为可以在前台运行的cron作业)。

3 个解决方案

#1


9  

Try this out on your user's crontab:

在用户的crontab上试试这个:

@hourly DISPLAY=:0 xterm -e /path/to/my/script.sh

It will open (hourly) an xterm with your script executing, and exit after your script exits. Of course, you should modify the @hourly part to suit your needs.

它将在您的脚本执行时打开(每小时)一个xterm,并在脚本退出后退出。当然,您应该修改@hourly部分以满足您的需求。

#2


2  

For GUI scripts in cron, try the following line in a shell:

对于cron中的GUI脚本,请在shell中尝试以下行:

crontab -e

Then in crontab :

然后在crontab中:

0 7 * * * DISPLAY=:0 /PATH/TO/SCRIPT

#3


1  

Assuming you are running X, you could always have it open a window on a selected display.

假设您正在运行X,您可以随时在所选显示器上打开一个窗口。

#1


9  

Try this out on your user's crontab:

在用户的crontab上试试这个:

@hourly DISPLAY=:0 xterm -e /path/to/my/script.sh

It will open (hourly) an xterm with your script executing, and exit after your script exits. Of course, you should modify the @hourly part to suit your needs.

它将在您的脚本执行时打开(每小时)一个xterm,并在脚本退出后退出。当然,您应该修改@hourly部分以满足您的需求。

#2


2  

For GUI scripts in cron, try the following line in a shell:

对于cron中的GUI脚本,请在shell中尝试以下行:

crontab -e

Then in crontab :

然后在crontab中:

0 7 * * * DISPLAY=:0 /PATH/TO/SCRIPT

#3


1  

Assuming you are running X, you could always have it open a window on a selected display.

假设您正在运行X,您可以随时在所选显示器上打开一个窗口。