[[+content_image]]
V
V
VN2021-11-08 12:11:00
bash
VN, 2021-11-08 12:11:00

How to check if a message has already been sent?

I check which process consumes the most memory, and I want to send the result to the mail or xmpp server, as in this case

if [[ $(ps aux | awk '{print $4}' | sort -nr | head -n 1 | sed 's/\..*//g' ) -ge 70 ]] ;\
 then ps aux | awk '$4>70' | sendxmpp -s 'Memory Load > 70%'  [email protected] ; \
fi

But if the process loads the memory constantly, then the messages will be sent non-stop.

Tell me how to check that the message has already been sent, if the process is still loading memory?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
G
ge, 2021-11-08
@kavabangaungava

For notifications, you can create a lock file (just like a flag). This is how it should work (in the example we are talking about a service crash, but the essence is the same):
1. the first iteration went
- the service crashed
- check for the existence of a lock file
- the notification about the crash is gone, since the lock file does not exist
- the lock file is created
2 .the second iteration started -
the service is still down
- checking for the existence of the lock file - the
lock file exists, so we will not send the notification again that the service has risen - delete the lock file 4. the cycle continues ...
The lock file can be any file, I usually created an empty file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question