Why can't I receive a trap from localhost? - snmp

I'm trying to send an SNMP trap from localhost TO localhost. I can't see it coming with tcpdump. I'm using the snmptrap command.
I've covered following scenarios :
Host A send trap to Host B = I get the trap
Host B send trap to Host A = I get the trap
Host A send trap to localhost = I can't get the trap !
Host B send trap to localhost = I can't get the trap !
Host A send a trap to an other network adapter on the host from another subnet = Still can't get the trap.
Is it a configuration issue ?
Tnx

Related

How to use tcp pseudo device to check if docker-compose service is available?

I have a kafka service listening on port 9092, and I want to create an automated script that will check to see if kafka is up and listening before moving on to creating schemas. I was messing around with something like bash -c '</dev/tcp/kafka/9092 &>/dev/null' but I wasn't able to get something working.
I'd like to be able to have a while <port not available> sleep 5 type statement to put in my script if possible.
If your service is handled by the system service manager (e.g: systemd or init.d), check the servcies status :
# your options may vary if the service is installed as a user service:
systemctl status kafka
service kafka status
There are several ways to check if some process is listening on a given port :
for local processes, use netsat or ss :
netstat -tlnp | grep ':9092'
# netstat options :
# t: list tcp sockets (add 'u' if you also want udp sockets)
# l: list listening sockets
# n: don't try to turn ips or ports into hostnames or known
# p: show pid (if you can access that process details;
# you may need to sudo if you want to list any process)
or use a tool like netcat to see if you can start a tcp connection:
if nc -z [host] 9092; then
echo "something is listening"
else
echo "nothing is listening"
fi
# a direct way to change your loop is :
while ! nc -z localhost 9092; do
sleep 1
done

how to stop ssh script when golang ssh session is disconnect with remote server

When I using golang ssh into one server, found my ssh session between golang program and remote server disconnect with error (wait: remote command exited without exit status or exit signal).
So I done a test, after golang program build a connection with remote ubuntu server, I login that server, and using
kill -9 <ssh-session pid>
to kill that ssh session, and the golang program return the same error
wait: remote command exited without exit status or exit signal
However, I found the ssh script that golang program had sent into remote server are still running. That is not what I want, I just want to stop the ssh script together with ssh session's disconnection.
How can I stop the ssh scripts' running when the ssh session's end?

Bash script to write to unix socket and then read a response but ONLY AFTER the welcome message

I am connecting to a server that initiates an SSH tunnel for me so I can connect to a remote device.
I can do an interactive socat connexion and manually issue commands like this:
Connected to soundwave server v131 (welcome message)
tunnel r 7 localhost:22 (my command)
Attempting to initiate a tunnel session ID [55] on local port 30054. (response)
The text in parenthesis is just my notes. They aren't actually part of the commands or responses.
I know I can send a message to a unix socket using socat
echo "tunnel r 7 localhost:22" | socat UNIX-CONNECT:data/files/monitor.socket STDOUT
And I saw some posts about being able to write a command and read a command with socat.
But the software has limitations that it only listens for commands until after the welcome message is issued.
So, is there a way with socat, nc, or any other tool to connect to a unix socket automatically, read the welcome message, write the tunnel command, and then parse the response to get the port so I can open up an SSH session?
Thanks so much.

Terminate Curl Telnet session in bashscript

Working on automating telnet connectivity from various hosts running the script from specified host with curl telnet call.
However as are aware for telnet once we get connected status for any hosts we have to pass an escape character to terminate the telnet sessions, but in bash script I need to terminate the session as soon as we get Connected/Refused response from the target endpoint or after some seconds of running the telnet session .
PFB Script where telnet connectivity is checked through Curl call, so I need is there anyway in curl that we can terminate the telnet session in curl as soon as we get the response or terminate the session in some milliseconds/seconds.
Code:
#!/bin/bash
HOSTS='LPDOSPUT00100 LPDOSPUT00101'
for S in ${HOSTS}
do
echo "Checking Connectivity From Host : ${S}"
echo ""
ssh -q apigee#${S} "curl -v telnet://${TargetEndPoint}:${Port}"
done
You could run it in the timeout command to make it terminate after a certain amount of time.
ssh -q apigee#"$S" "timeout 5s curl -v telnet://${TargetEndPoint}:${Port}"
would terminate it after 5 seconds if it hadn't already exited on its own.
Perhaps curl isn't the right tool for this job though. Have you considered using nc instead?
ssh -q apigee#"$S" "nc -z ${TargetEndPoint} $Port"
will likely do what you want.

Telnet : connect, send command and exit in just one line

I try to use telnet in a script (to be use in python program). I want to do the connection, send a command, and exit the connection in juste one line. The command i want to send is to start a program on a remote machine but I d'ont want to wait the end of this program to exit the telnet connection.
I try to do : "echo myCommand | netcat 192.168.1.50 23" but it waits the end of the program.
thanks for your help
Use bash builtin tcp socket feature:
echo yourCommand >/dev/tcp/192.168.1.50/23

Resources