I was trying to find a command for "leaving copy-mode" from this page, but it seems only the key binding prefix+q exists for this function; i.e., I can't find the associated :command-style command.
Does this mean it is impossible to bind another key to "leave copy-mode"? I'd like to bind the Esc key.
Copy mode uses its own set of commands, separate from tmux itself. Use send-keys -X to "type" commands in copy mode, as demonstrated by the default binding for exiting copy mode:
bind-key -T copy-mode q send-keys -X cancel
Note that Escape is already bound to the same command, at least in tmux 2.7.
% tmux list-keys | grep "send-keys -X cancel"
bind-key -T copy-mode C-c send-keys -X cancel
bind-key -T copy-mode Escape send-keys -X cancel
bind-key -T copy-mode q send-keys -X cancel
bind-key -T copy-mode-vi C-c send-keys -X cancel
bind-key -T copy-mode-vi q send-keys -X cancel
The page you were referring to is not a comprehensive list of tmux commands, but rather a comparison of how to accomplish some common tasks in different terminal multiplexers.
Related
Is there a way to add gitlab variables to the command ?
eg: variables: ARTIFACTORY_ADDRESS: "a.com"
script:
sshpass -p "password" ssh -o "StrictHostKeyChecking=no" user#SERVER 'echo $ARTIFACTORY_ADDRESS'
Currently its not taking the value from the variable and printing $ARTIFACTORY_ADDRESS in the console. I want the value to be printed in the console
Check first if using double-quotes would help enabling variable substitution:
sshpass -p "password" ssh -o "StrictHostKeyChecking=no" user#SERVER \
"echo $ARTIFACTORY_ADDRESS"
^^^ ^^^
I am trying to run the following command in karate using karate.fork
ssh -o ProxyCommand="ssh -W %h:%p -i ~/.ssh/id_rsa root#myjumphost" -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -o PasswordAuthentication=no root#finaldest echo test
I have broken this up into an array to pass to karate.fork like so:
[
ssh,
-o,
ProxyCommand="ssh -W %h:%p -i ~/.ssh/id_rsa root#myjumphost",
-i,
~/.ssh/id_rsa,
-o,
StrictHostKeyChecking=no,
-o,
PasswordAuthentication=no,
root#finaldest,
echo test
]
Then run the command like so:
* karate.fork(args) where args is the array mentioned above
The command works when I paste it into the terminal and run it manually, however when run with karate.fork I get
zsh:1: no such file or directory: ssh -W finaldest:22 -I ~/.ssh/id_rsa root#myjumphost
kex_exchange_identification: Connection closed by remote host
I have tried adding a few backslashes before the " in the ProxyCommand but no amount of back slashes fixes this issue. I think I am misunderstanding what karate.fork is doing to run the command, is there some internal parsing or manipulating of the given input? I was able to get this command to work when I used useShell: true however this option breaks other tests for me so I would really like to avoid it.
I had to remove the double quotes, seems like they didn't play well with karate.fork and the command still runs without them
[
ssh,
-o,
ProxyCommand=ssh -W %h:%p -i ~/.ssh/id_rsa root#myjumphost,
-i,
~/.ssh/id_rsa,
-o,
StrictHostKeyChecking=no,
-o,
PasswordAuthentication=no,
root#finaldest,
echo test
]
I am passing command line arguments to a shell file i.e assignRole.sh which contains an SQL command which will use these arguments like below
ssh -o StrictHostKeyChecking=no -T $key < /oracle/oracle_user/makhshif/./assignRole.sh name open_mode >> /oracle/oracle_user/dftest.txt
This gives me error and does not accept arguments of name and open_mode and gives error, but if I execute the statement outside of ssh command like:
/oracle/oracle_user/makhshif/./assignRole.sh name open_mode
This runs fine
What is the problem with ssh command and how should I adjust these parameters so these can be accepted for the shell script assignRole.sh
< /oracle/oracle_user/makhshif/./assignRole.sh
This commands sends a content of that file to stdin. So obviously it can't process variables that you haven't send to remote machine. Just preprocess your script or create a script on remote machine and call it with arguments
Though it's even easier to pass variables like this:
ssh -o StrictHostKeyChecking=no -T $key "var1=$var1 var2=$var2" < /oracle/oracle_user/makhshif/./assignRole.sh name open_mode >> /oracle/oracle_user/dftest.txt
For example my function for executing update scripts on all cluster nodes:
# functions:
ssh_exec(){
local DESCR="$1"; shift
local SCRIPT="$1"; shift
local hosts=("$#")
echo =================================================
echo = $DESCR
echo = Going to execute $SCRIPT...
read -a res -p "Enter 'skip' to skip this step or press Enter to execute: "
if [[ $res = "skip" ]]
then
echo Skipping $SCRIPT...
else
echo Executing $SCRIPT...
for host in "${hosts[#]}"
do
local cur=${!host}
echo Executing $SCRIPT on $host - $cur...
sshpass -p "$rootpass" ssh -o "StrictHostKeyChecking no" root#${cur} \
"ns1=$ns1 ns2=$ns2 search=$search zoo1=$zoo1 zoo2=$zoo2 zoo3=$zoo3 node0=$node0 pass=$pass CURIP=$cur CURHOST=$host bash -s" \
<$SCRIPT >log-$SCRIPT-$cur.log 2>&1
echo Done.
done
echo =================================================
fi
}
Then I use it like this:
read -p "Please check that Solr started successfully and Press [Enter] key to continue..."
#Solr configset and collections:
ssh_exec "Solr configset and collections" script06.sh zoo1 zoo2 zoo3
This command executes script06.sh on 3 servers (zoo1,zoo2,zoo3)
As Sayan said, using < redirects the output of running the assignRole.sh script locally, but you want to execute that script on the remote host, with the arguments.
Pass the whole command as the final argument to ssh, in quotes:
ssh -o StrictHostKeyChecking=no -T $key "/oracle/oracle_user/makhshif/./assignRole.sh name open_mode" >> /oracle/oracle_user/dftest.txt
or split into multiple lines for readability:
ssh -o StrictHostKeyChecking=no -T $key \
"/oracle/oracle_user/makhshif/./assignRole.sh name open_mode" \
>> /oracle/oracle_user/dftest.txt
I have several tmux panes running in a window that have been started with syntax like:
tmux split-window -h -l {dynamic value} tail -f somefile.txt
tmux split-window -v -l {dynamic value} tail -f someotherfile.txt
tmux split-window -h -l {dynamic value} nc -l -p {random port}
As I use this script to create new panes and I need to update an array in my script with the sizes of each "window" (pane).
If the tmux panes contained interactive shells, I could just run tput cols and tput rows in them to get the size. I checked the tmux man page, but didn't see the commands I'm looking for.
If you know a pane’s id (e.g. %24) or its name (e.g. session_name:win_idx.pane_idx; see target-pane in the man page), then you can use display-message -p to query the dimensions:
tmux display-message -pt "$pane" -F '#{pane_width}x#{pane_height}'
If you do not already have a way to name to panes, then you can collect the pane ids as you split them off by using the -P option along with the -F option:
pane_a=$(tmux split-window -PF '#{pane_id}' -hl "$dynamic_value" 'tail -f somefile.txt')
⋮ # create other panes
pane_a_width=$(tmux display-message -pt "$pane_a" -F '#{pane_width}')
If you want to know about all the panes in a window, then you can use list-panes with the window’s id (e.g. #5) or name (e.g. session_name.win_idx; see target-window in the man page):
tmux list-panes -t "$window" -F '#{pane_id} #{pane_width}x#{pane_height} #{session_name}:#{window_index}.#{pane_index}'
Some of these options and format specifiers are not available on old versions of tmux, but there are usually workarounds (depending on just how old your version is).
Using "screen -D -R -S foo", one can attach to an existing session named "foo", or if said session doesn't exist, create it.
How does one also source a file that contains screen commands?
I thought that this would work:
screen -D -R -S foo -X source file
Unfortunately, that fails with this message:
No screen session found.
EDIT: As zebediah49 pointed out in a comment, I left out the "source" in "-X source file" by mistake. Updated now.
OK, from a close reading of the man page I note:
-X Send the specified command to a running screen session. You can
use the -d or -r option to tell screen to look only for attached
or detached screen sessions. Note that this command doesn't work
if the session is password protected.
running screen session. In other words, I don't believe you can do what you're looking for like that, with only one command. However, you can
create the window if it does not exist
send the command to the window
connect to the window:
NL=$'\n'
NAME=foo
screen -ls | grep "$NAME" || screen -d -m -S "$NAME"
screen -r "$NAME" -X stuff "source file$NL"
screen -D -R -S "$NAME"
(Clarification of how -X works, from Send commands to a GNU screen )