I'm using a tmux script in bash that has the following code:
tmux send-keys -t d4 'tmux send-keys -t "server1 tail -F /var/log/file.log | grep --line-buffered keyword | egrep --line-buffered "Two keywords" | /root/another_app" ENTER' ENTER
When the line is passed to tmux, "Two keywords"
is transformed in Twokeywords
.
I've tried to escape the quotes to no avail.
The same is happening to a more complex line, which is:
tmux send-keys -t d4 'tmux send-keys -t server2 "tail -F /var/log/file2.json | grep --line-buffered -a '"event_type":"keyword"' | /root/another_app" ENTER' ENTER
Also no luck in escaping the quotes.
My objective is to have the first line be sent to tmux as:
tail -F /var/log/file.log | grep --line-buffered keyword | egrep --line-buffered "Two keywords"
and the second line as
tail -F /var/log/file2.json | grep --line-buffered -a '"event_type":"keyword"'
please try this:
tmux send-keys -t d4 'tmux send-keys -t "server1 tail -F /var/log/file.log | grep --line-buffered keyword | egrep --line-buffered '"'Two keywords'"' | /root/another_app" ENTER' ENTER
because:
echo 'tmux send-keys -t "server1 tail -F /var/log/file.log | grep --line-buffered keyword | egrep --line-buffered '"'Two keywords'"' | /root/another_app" ENTER'
tmux send-keys -t "server1 tail -F /var/log/file.log | grep --line-buffered keyword | egrep --line-buffered 'Two keywords' | /root/another_app" ENTER
Are sure with two ENTER at the end?
For the second one you might use a here document to assign your special tmux parameter to a variable and then call your tmux with this variable:
var=$(cat <<SETVAR
'tmux send-keys -t server2 "tail -F /var/log/file2.json | grep --line-buffered -a '"event_type":"keyword"' | /root/another_app" ENTER'
SETVAR
)
echo "$var"
'tmux send-keys -t server2 "tail -F /var/log/file2.json | grep --line-buffered -a '"event_type":"keyword"' | /root/another_app" ENTER'
so try then
var=$(cat <<SETVAR
'tmux send-keys -t server2 "tail -F /var/log/file2.json | grep --line-buffered -a '"event_type":"keyword"' | /root/another_app" ENTER'
SETVAR
)
tmux send-keys -t d4 "$var" ENTER