[英]how to write a shell command to execute a command in an ALREADY open terminal window
I have a process that depends on the internet, which dies randomly due to a spotty connection.我有一个依赖于互联网的过程,由于连接不稳定,它会随机死亡。
I am writing a cron script, so that it checks every minute if the process is running, and restarts it...我正在编写一个 cron 脚本,以便它每分钟检查一次进程是否正在运行,然后重新启动它......
the process doesn't kill the terminal window it's in.该过程不会杀死它所在的终端 window。
I don't want to kill the terminal - then spawn a new one.我不想杀死终端 - 然后产生一个新终端。
I want the shell script I'm writing to execute in the window that's already open...我想要我正在编写的 shell 脚本在已经打开的 window 中执行...
I'm using i3-sensible-terminal right now, but any terminal would do.我现在正在使用 i3-sensible-terminal,但任何终端都可以。
if ! ps -a | grep x123abc > /dev/null ; then
$CMD
fi
I have not yet located the information I need to have that run in a specific terminal.我还没有找到在特定终端中运行所需的信息。
changing the CMD to include a terminal seems to only open up a new window...将 CMD 更改为包含一个终端似乎只会打开一个新的 window ...
Suggesting a different design to separate running your script from observing your script output.建议使用不同的设计将运行脚本与观察脚本 output 分开。
Write script named worker
"that depends on the internet, which dies randomly due to a spotty connection."编写名为
worker
的脚本“它依赖于互联网,由于连接不稳定,它会随机死亡”。 appends ALL its output to log file \home\$USER\worker.log
.将其所有output 附加到日志文件
\home\$USER\worker.log
。 Or just redirect ALL output from script named worker
to log file \home\$USER\worker.log
.或者只是将所有output 从名为
worker
的脚本重定向到日志文件\home\$USER\worker.log
。
worker > \home\$USER\worker.log 2>&1
Run script name worker
as a restartable service with systemd
unit service.使用
systemd
单元服务将脚本名称worker
作为可重新启动的服务运行。
Here is a good article explaining this practice: https://dev.to/setevoy/linux-systemd-unit-files-edit-restart-on-failure-and-email-notifications-5h3k这是一篇解释这种做法的好文章: https://dev.to/setevoy/linux-systemd-unit-files-edit-restart-on-failure-and-email-notifications-5h3k
Continue to observe the log file \home\$USER\worker.log
using tailf
command使用
tailf
命令继续观察日志文件\home\$USER\worker.log
tailf \home\$USER\worker.log
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.