Hay*_*yat 1 linux cron python-3.x tmux
我正在尝试在tmux会话中运行 python 脚本。我写了一个命令 ( tmux new-session -d -s my_session),它从crontab.
但是当我尝试使用tmux new-session -d -s my_session 'python3 test.pyor运行 python 或 shell 文件时tmux new-session -d -s my_session 'sh test.sh
,脚本没有运行。我使用了这里的参考。请帮我解决一下这个。
编辑
您可以用 分隔 tmux 命令\;,然后使用该send-keys命令将命令发送到活动窗口。
在您的情况下,您可以使用:
tmux new-session -d -s my_session \; send-keys "python3 test.py" Enter
tmux new-session -d -s my_session \; send-keys "sh test.sh" Enter
tmux new-session -d -s my_session \; send-keys "python3 -m http.server 8080" Enter
Run Code Online (Sandbox Code Playgroud)
您可以send-keys在tmux 联机帮助页部分找到有关send-keys选项的更多信息:
send-keys [ -lMRX ] [ -N repeat-count] [ -t target-pane] key ...
(别名:send)
将一个或多个键发送到窗口。每个参数键是要发送的键的名称(例如“C-a”或“NPage”);如果字符串未被识别为键,则将其作为一系列字符发送。该-l标志禁用键名称查询和字面发送键。所有参数都从第一个到最后一个顺序发送。该-R标志使终端状态被复位。-M传递鼠标事件(仅当绑定到鼠标键绑定时才有效,请参阅MOUSE SUPPORT)。
-X用于将命令发送到复制模式 - 请参阅WINDOWS AND PANES部分。
-N指定重复计数。
在send-keys语法上所描述的键绑定部分中的TMUX手册页。使用的键名与 使用的键名send-keys相同bind-key。
我通常在基本文件之上使用不同的配置文件。
想象一下,您在~/.tmux.confI 中有 tmux 配置,然后在我的~/.tmux/文件夹中创建不同的配置文件。作为一个例子,我可以有一个 python 配置文件(attach如果你想在会话中输入,请使用):
# To use this configuration launch tmux with the command:
# > tmux -f ~/.tmux/python.conf attach
#
# Load default tmux config
source-file ~/.tmux.conf
# Create session and launch python script
new-session -s python -n python -d -c ~/src/python/
send-keys "python test.py" Enter
Run Code Online (Sandbox Code Playgroud)
这使我可以灵活地创建更复杂的会话。