Friday, April 26, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 4160  / 2 Years ago, fri, november 4, 2022, 7:52:58

I am trying to create a cron job that would allow me to monitor the status of a particular port and send out notification via email while it changes from listening state to anything else.


More From » cron

 Answers
0

In the simplest case, you could run a command like this:



lsof -i :22 | grep LISTEN


So, to have that run every 5 minutes and send an email if the port is not listening, add this to your crontab:



*/5 * * * * lsof -i :22 | grep LISTEN || echo "Not listening" | mail [email protected]


This, of course, assumes that you have already set up your machine for the mail command.


[#22820] Saturday, November 5, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eeperant

Total Points: 39
Total Questions: 106
Total Answers: 117

Location: Finland
Member since Sat, Dec 5, 2020
3 Years ago
;