From 7b4780ef70cdafff193745a09c13beaf54f65bba Mon Sep 17 00:00:00 2001 From: fanta Date: Wed, 2 Feb 2022 18:18:06 +0100 Subject: [PATCH] funcionando --- sshMonitor.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sshMonitor.sh b/sshMonitor.sh index 9f1704c..3fcf1b8 100755 --- a/sshMonitor.sh +++ b/sshMonitor.sh @@ -1,9 +1,13 @@ #!/usr/bin/env bash +fileSSHConnections="/tmp/.sshActualConnections" +logDir="/tmp/" + main(){ checkRoot - haveProgram strace wget lsof + haveProgram strace wget lsof awk printActualSSHConnections + monitoringSocket } checkRoot(){ @@ -15,7 +19,17 @@ haveProgram(){ } printActualSSHConnections(){ - lsof -c ssh 2>/dev/null | grep IPv4 | awk '{ print $2,$9 }' | cat -n | tee $tmpFileSSHConnections + lsof -c ssh 2>/dev/null | grep IPv4 | awk '{ print $2,$9 }' | cat -n | tee $fileSSHConnections +} + +monitoringSocket(){ + if [ $(wc -l $fileSSHConnections | cut -d " " -f 1) != 0 ];then + read -p "Enter option number: " nOption + pidSSH=$(cat $fileSSHConnections | awk '{ print $2 }' | head -n $nOption | tail -n 1) + strace -p $pidSSH | tee -a $logDir/sshMonitor-$pidSSH.log + else + echo "No ssh connection found" + fi } main