lis67-support-app/webapp/get_port.sh

7 lines
332 B
Bash

#!/bin/bash
user=$1
if [[ -z $user ]]; then exit 1; fi
for p in $(netstat -tulpn | grep "sshd: $user" | grep -v tcp6 | awk -F" " '{print $4}' | cut -d':' -f 2); do
timeout 2 ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=2 -i id_rsa -p $p lis67_support@localhost "exit 0" > /dev/null && echo $p && exit 0
done