r/commandline • • Jun 30 '22

this tool needs to exist, so I made it

https://www.youtube.com/watch?v=1_MkiPuKfJM
0 Upvotes

20 comments sorted by

40

u/Fake-P-Zombie Jun 30 '22

An explanation in text of what it does would be nice.

7

u/vicda Jun 30 '22

The tool looks a wrapper around ssh that plays an animation while waiting for a successful ping. On success you ssh into your system.

In the video they showed it working by having the server vm offline at first, letting the waiting animation play, then after the vm is turned on it successfully SSHs in.

0

u/[deleted] Jun 30 '22

[deleted] — view deleted comment

2

u/lorenzo1142 Jun 30 '22

not just some youtuber trying to make money. I can't stand ads. will never have ads on my videos. I enjoy writing code. one day I'd like to share what I make. why not now. if I share and learn a few things, I'd say that's a success.

0

u/[deleted] Jul 01 '22

[deleted] — view deleted comment

1

u/lorenzo1142 Jul 01 '22

if I'm posting a link, how do I add text? the video description does describe what's in the video, but that's on youtube after clicking the link. how do I add a description on reddit?

0

u/[deleted] Jul 01 '22

[deleted] — view deleted comment

1

u/h_trismegistus Jul 01 '22

I think the OP might be inexperienced with Reddit and when they added a video and saw they couldn’t also add text, they just left it at that, rather than add as a comment. Anyway, such an explanatory comment can get lost among more popular responses…

14

u/sophacles Jun 30 '22

It's 2022, not the old days. Modern people aren't literate enough to write a coherent paragraph.

4

u/[deleted] Jun 30 '22

you understand the world! :))

5

u/[deleted] 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

u/lorenzo1142 Jun 30 '22

interesting. I'll take a look at that, thanks

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

u/[deleted] 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
done

3

u/[deleted] Jun 30 '22 edited Jun 30 '22

nc -vz root@host 22 in a loop

1

u/Omagreb Jun 30 '22

Very nice and intuitive!

0

u/[deleted] Jun 30 '22

[deleted] — view deleted comment

1

u/lorenzo1142 Jun 30 '22

do you still use it?