0

I have in my cron that auto starts a service inside a tmux if it detects that its not running. The rest of my bash script works, but if the tmux session doesn't exist, it throws an error. Which is why I added in "tmux new ENTER" below. But it still doesn't start tmux session. If I manually started the tmux session, the code works and it will execute the send-keys command.

I'm trying to see why the tmux new session doesn't start on cron. Any ideas?

  /usr/bin/pkill -9 java
  /usr/bin/tmux new ENTER
  sleep 3
  /usr/bin/tmux send-keys -t 0 "cd /home/xxx/bbb;./run.sh" ENTER
  echo "$(date) ${1} RESTARTED NODE"

1 Answer 1

2

Use /usr/bin/tmux new-session -d -s ENTER and for good measure follow it up with /usr/bin/tmux detach -s ENTER.

So your script would look like:

  /usr/bin/pkill -9 java
  /usr/bin/tmux new-session -d -s ENTER
  /usr/bin/tmux detach -s ENTER
  sleep 3
  /usr/bin/tmux send-keys -t 0 "cd /home/xxx/bbb;./run.sh" ENTER
  echo "$(date) ${1} RESTARTED NODE"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .