简体   繁体   English

在crontab中使用linux命令输出

[英]Use linux command output in crontab

I made a shell script and registered to execute every 20 minutes. 我制作了一个shell脚本并注册为每20分钟执行一次。 Here is my crontab code. 这是我的crontab代码。

*/20 * * * * sh /mypath/run_myprocess.sh &> /dev/pts/34

I editted code like this in order to see whether my process run correctly. 我编辑了这样的代码,以查看我的进程是否正确运行。

I get the result '/dev/pts/34' from tty command in terminal. 我从终端的tty命令得到结果'/ dev / pts / 34'。

However, does anyone know how to use linux command results(in this case: /dev/pts/34) in crontab? 但是,有谁知道如何在crontab中使用linux命令结果(在这种情况下为/ dev / pts / 34)? This is because I will use several terminal to run my tasks. 这是因为我将使用多个终端来运行任务。

For example, in shell script, I can use linux command result in the form of $(command) such as 例如,在shell脚本中,我可以使用$(command)形式的linux命令结果,例如

echo "$(date)"

directly. 直。

Plus, if I type something on the terminal during process running with crontab, it actually gives result. 另外,如果我在使用crontab运行的过程中在终端上键入内容,它实际上会产生结果。 For example, 例如,

Process is running........

ls
backup backup.sh Desktop Task_Folder shared_folder
[UserID] ~ # 

So I guess cron jobs run correctly but in background. 因此,我想cron作业可以正常运行但在后台运行。 Please help me to find out how can I bring cron jobs in foreground. 请帮助我找出如何将Cron作业置于前台。

If you start a job on your console and background it you can then bring it to foreground. 如果您在控制台上启动作业并使其后台运行,则可以将其置于前台。 If the task is not yours or not started on your terminal then you can not. 如果该任务不是您的任务或不在终端上启动,则您将无法执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM