You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			36 lines
		
	
	
		
			911 B
		
	
	
	
		
			Bash
		
	
			
		
		
	
	
			36 lines
		
	
	
		
			911 B
		
	
	
	
		
			Bash
		
	
#!/usr/bin/env bash
 | 
						|
 | 
						|
fileSSHConnections="/tmp/.sshActualConnections"
 | 
						|
logDir="/tmp/"
 | 
						|
 | 
						|
main(){
 | 
						|
  checkRoot
 | 
						|
  haveProgram strace wget lsof awk
 | 
						|
  printActualSSHConnections
 | 
						|
  monitoringSocket
 | 
						|
}
 | 
						|
 | 
						|
checkRoot(){
 | 
						|
  if [ "$(whoami)" != "root" ]; then echo -e "\e[31m\e[1m[NOT OK]\e[0m Run it with root please" && exit ; fi
 | 
						|
}
 | 
						|
 | 
						|
haveProgram(){
 | 
						|
  for i in $@; do type $i &> /dev/null ; if [ $? == 1 ]; then echo "$i not found. Please install it"; fi ; done
 | 
						|
}
 | 
						|
 | 
						|
printActualSSHConnections(){
 | 
						|
  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
 |