Binding keys to operate on a specific pane - key-bindings

I have this key binding:
bind -rn C-Down last-pane \; send-keys "PageDown" \; last-pane
bind -rn C-Up last-pane \; send-keys "PageUp" \; last-pane
It works but I don't want it bound to the last-pane, I want it set the pane id I have in a variable: #tmux_man_pane.
Tried this:
bind -rn C-Down send-keys PageDown -t #tmux_man_pane
bind -rn C-Up send-keys PageUp -t #tmux_man_pane
And this:
bind -rn C-Down showw -v #tmux_man_pane \; send-keys "PageDown" \; showw -v #tmux_man_pane
bind -rn C-Up showw -v #tmux_man_pane \; send-keys "PageUp" \; showw -v #tmux_man_pane
Neither worked.

bind -rn C-Down run "tmux send-keys -t #{#tmux_man_pane} PageDown"

Related

Ho can I recreate all my running containers in a single shot?

I have multiple containers which are running. I changed the docker log driver and want all my running containers to start using the new configuration. In docker's documentation, they said all containers must be recreated. I keep my applications in multiple folders, so I can't recreate them with a single command.
I have to go to each of the following folders one by one:
/home/docker/folder1
/home/docker/folder2
/home/docker/folder3
Then run the following command:
/usr/local/bin/docker-compose down
/usr/local/bin/docker-compose up -d
Is there any workaround?
I tried:
# /usr/local/bin/docker-compose down
ERROR:
Can't find a suitable configuration file in this directory or any
parent. Are you in the right directory?
Supported filenames: docker-compose.yml, docker-compose.yaml
You can list all running container and "give" them to docker container restart. For example:
docker container restart $(docker container ls --quiet)
If you only want to do it for container created by compose, use can filter by label
docker container restart \
$(docker container ls --quiet --filter label=com.docker.compose.project)
Alternatively, you can search for all compose files, and do something with them, for more advanced commands. Maybe this is required, if restart does not suffice.
find /home/docker -name docker-compose.yaml -type f \
| while read -r f; do
docker compose --file "$f" up --force-recreate -d
done
Or with xargs
find /home/docker -name docker-compose.yaml -type f \
| xargs --no-run-if-empty -I{} docker compose --file {} up --force-recreate -d
If you have jq installed, you could get the path to the compose files more reliably by using docker compose ls with the JSON formatted output
docker compose ls --format json \
| jq -rc 'map(.ConfigFiles) | .[]' \
| xargs -r -I{} docker compose -f {} up --force-recreate -d
If you want to take care of the name as well, you need to use that from the output too.
docker compose ls --format json \
| jq -c '.[]' | while read -r config; do
docker compose \
-p "$(echo "$config" | jq -r '.Name')" \
-f "$(echo "$config" | jq -r '.ConfigFiles')" \
up --force-recreate -d
done
This is still not 100% solid since you may have used more than 1 config file. In that case, you can replace the commas with colons in the ConfigFiles and set the env variable COMPOSE_FILE
docker compose ls --format json \
| jq -c '.[]' | while read -r config; do
COMPOSE_FILE="$(echo "$config" | jq -r '.ConfigFiles' | tr -s , :)" \
docker compose \
-p "$(echo "$config" | jq -r '.Name')" \
up --force-recreate -d
done
There is still one problem that you can't overcome that way, if you have used specific profiles, you have no way of knowing which ones. So hopefully docker container restart is enough, as it would avoid most issues related to finding compose files and using compose.

Can't get shell script that works directly working in crontab

I've written a script to backup my docker mysql containers:
export $(grep -v '^#' .env | xargs -d '\n')
filename=$(date +'%Y%m%d_%H%M%S')
docker-compose exec mysql bash -c "mysqldump --user=$MYSQL_USERNAME --password='$MYSQL_PASSWORD' --ignore-table=$MYSQL_DATABASE.forums_readData_forums_c --ignore-table=$MYSQL_DATABASE.forums_readData_newPosts $MYSQL_DATABASE | gzip > /tmp/$filename.gz"
mysql_container=$(docker ps | grep -E 'mysql' | awk '{ print $1 }')
docker cp $mysql_container:/tmp/$filename.gz $BACKUP_DIR/mysql/
docker-compose exec mysql rm /tmp/$filename.gz
sudo find $BACKUP_DIR/mysql/* -mtime +30 -exec rm {} \;
But when I add it to the crontab, I get the error the input device is not a TTY. That's coming from the docker-compose exec command, except there's no -it flag? When I run this script directly from the shell ./backup.sh, it works fine.

Filter a PCAP file using tshark : show ip source>ip destination:info in a txt file

I need a tshark command so i can create a txt file containing Ipsource>Ipdestination:Info in this order ! i tried this command
tshark -T fields -n -r "C:\Users\dell\Desktop\tracecomplete.pcap" -E separator=, -e ip.src -e ip.dst > "C:\Users\dell\Desktop\walima22.txt"*
but i can't change the separator and show the infos
There are generally 2 solutions for printing specific column data, one using column-specifiers and the other using fields, similar to what you have.
Using column-specifiers:
Standard specifiers as described by tshark.exe -G column-formats:
tshark.exe -n -r "C:\Users\dell\Desktop\tracecomplete.pcap" -o "gui.column.format:\"Source\",\"%s\",\"Destination\",\"%d\",\"Info\",\"%i\""
... or using custom columns for those fields that are supported:
tshark.exe -n -r "C:\Users\dell\Desktop\tracecomplete.pcap" -o "gui.column.format:\"Source\",\"%Cus:ip.src\",\"Destination\",\"%Cus:ip.dst\",\"Info\",\"%i\""
Using Fields:
tshark.exe -n -r "C:\Users\dell\Desktop\tracecomplete.pcap" -T fields -E separator=, -e ip.src -e ip.dst -e _ws.col.Info
but i can't change the separator
You should be able to change it using the -E option. Refer to the tshark man page for more help with this option.

How to write noncapturing groups in egrep

The following command does not correctly capture the 16714 from 16714 ssh -f -N -T -R3300:localhost:22
egrep -o '^[^ ]+(?= .*[R]3300:localhost:22)'
(However swapping to grep does if you use the -P flag. I was expecting egrep to be able to handle this)
grep -P forces grep to use the Perl regexp engine.
egrep is the same as grep -E and it forces grep to use the ERE (extended regular expression) engine, that does not support lookahead.
You can find a quick reference of the differences between Perl and ERE (and others) here : http://www.greenend.org.uk/rjk/tech/regexp.html
To handle this with POSIX grep, you would use grep to isolate the lines of interest and then use cut to isolate the fields of interest:
$ echo "16714 ssh -f -N -T -R3300:localhost:22" | grep 'R3300:localhost:22' | cut -d' ' -f1
16714
Or, just use awk:
$ echo "16714 ssh -f -N -T -R3300:localhost:22" | awk '/R3300:localhost:22/{print $1}'
16714

grep command not working with xargs and pipe usage

I am trying to list hijacked files using cleartool ls -recurse commands which seems not to work when symbolic links are present.
So trying to do something like below:
find -L -type f -print0 | xargs -0 cleartool ls
Which prints the cleartool ls output for each file as expected, but when I grep for "hijacked" it fails:
find -L -type f -print0 | xargs -0 cleartool ls | grep -i hijacked
It outputs nothing though there are hijacked files.

Resources