Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
592 views
in Technique[技术] by (71.8m points)

tmux can't find running server when executed from bash script

I have a simple bash script with many commands as below:

(cd /home/mc/ ;
echo msg-here ;
tmux send-keys -t mc "say xyz" ENTER ;
echo successful ;) > scripts/logs/$(date +%d-%m-%Y).txt

When executing the script, I get the result of no server running on /tmp/tmux-0/default in my terminal, despite the fact I can execute tmux send-keys -t mc "say xyz" ENTER from the terminal with no problems.


Notes
  • I am running the script and the command from the same place (and both as the mc user).
  • Output to log file doesn't show the error message, but instead looks as if everything worked.

Thanks

question from:https://stackoverflow.com/questions/65919420/tmux-cant-find-running-server-when-executed-from-bash-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Attention: This is only a workaround - however it seems to work flawlessly for my use-case.

Method: I created a new bash script myscript-entry.sh which runs the main script as the actual user.

Contents of script follow.

su -c "/home/mc/myscript.sh" - mc

Execute sudo ./myscript-entry.sh from the directory containing both scripts (or anywhere since the "entry" script uses absolute path) and the tmux commands should now be executed properly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...