Search code examples
bashcrontmux

Attach and run script inside an existing tmux session


I want to have more control over a time consuming cron job running on a server. That is, be able to see progress, stop running code if necessary and etc..

I thought that this would be possible using a tmux session, but I can not figure out how.

I know that you can start new tmux sessions and run code inside it like this:

tmux new-session -d -s session_name "some code"

I've tried the obvious solution like this:

tmux new-session -s session_name
**exit session**
tmux a -t session_name "some code"

Is this even possible? Any advice is appreciated.


Solution

  • You could send the key to the tmux session:

    tmux send -t session_name ls ENTER
    

    if you need to send to a specific panel:

    tmux send -t session_name.(panelnumber) ls ENTER
    

    example:

    tmux send -t session_name.0 ls ENTER