r/commandline • u/lorenzo1142 • Jun 30 '22
this tool needs to exist, so I made it
https://www.youtube.com/watch?v=1_MkiPuKfJM5
Jun 30 '22
Github? AUR package?
2
u/aptupdate Jun 30 '22
2
u/TinyLebowski Jun 30 '22
FYI you can use
ssh -G {alias or user@host}to resolve the user/host/port. My .ssh/config only has one line:Include config.d/*1
1
u/lorenzo1142 Jun 30 '22
I renamed the repo to be a less common name, avoid conflicts. it was already renamed in other places, just not the github mirror.
https://github.com/PoiXson/pxnScripts-mirror/blob/master/src/pingssh.sh
-5
u/lorenzo1142 Jun 30 '22
can manually copy the script to /usr/bin/pingssh if you want, or can help me make a package. I'm only packaging for rpm at the moment.
1
u/lorenzo1142 Jun 30 '22
it's a simple thing, but has been very useful to me over the years. ssh somehost, oh it's not up yet. stick a p in front of it and hit enter again. I like quick and easy. I set an alias pssh, use it daily.
4
Jun 30 '22
I made something similar in bash I called wait_for_ssh.sh, I mostly use it for reboots
It supports ProxyCommand but has no handling for the proxy host being down. It also sends desktop notifications when the host is reachable again
#!/bin/bash
set -e -u
if [[ $# -lt 1 ]] || [[ "$1" == "--help" ]]; then
echo "Usage: $0 [ <host> | <user@host> ] [ <command> [ <command parameter> [ ... ] ] ]"
echo
echo "The command is run when the waiting is over"
exit 1
fi
host="$1"
shift
if [[ $# -gt 0 ]]; then
declare -a cmd
cmd=("$@")
fi
ssh_hostname="$(ssh -G "${host}" | grep '^hostname ' | sed -e 's/^hostname //')"
ssh_port="$(ssh -G "${host}" | grep '^port ' | sed -e 's/^port //')"
ssh_proxy_command="$(ssh -G "${host}" | grep '^proxycommand ' | sed -e 's/^proxycommand //')"
declare -a check_command
if [[ -n "${ssh_proxy_command}" ]]; then
check_command=($(echo "${ssh_proxy_command}" | sed -e 's/nc/nc -vz -w 3/' -e "s/%h/${ssh_hostname}/g" -e "s/%p/${ssh_port}/g"))
else
check_command=(nc -vz -w 3 "${ssh_hostname}" "${ssh_port}")
fi
count=0
start_time="$(printf "%(%s)T" -1)"
while true
do
now_time="$(printf "%(%s)T" -1)"
echo "Waiting for $(( now_time - start_time )) seconds"
count=$(( count + 1 ))
if "${check_command[@]}"; then
notify-send -a wait_for_ssh.sh -t 3000 -u low "Connection to ${host} works again" "Connection to host ${host} works again after ${count} tries and $(( now_time - start_time )) seconds at $(date '+%Y-%m-%d %H:%M:%S')"
"${cmd[@]}"
break
else
sleep 3
fi
done3
2
u/zfsbest Jun 30 '22
This is not that hard guys...
https://github.com/kneutron/ansitest/blob/master/ssh-wait4.sh
1
0
40
u/Fake-P-Zombie Jun 30 '22
An explanation in text of what it does would be nice.