'Ubuntu server 20.4 Error code=exited, status=7

I had tried to make ping-down monitoring system for my network ips, and if any loss of packet i should get the alert to teams webhook

/usr/bin/pingtest.sh

#!/bin/sh 

while read p; do

HOSTS="$p"
COUNT=4

pingtest(){
  for myHost in "$@"
  do
    ping -c "$COUNT" "$myHost" && return 1
  done
  return 0
}

if pingtest $HOSTS
then
        curl -H 'Content-Type: application/json' -d "{\"text\": \"($HOSTS) is  down (ping failed) at $(date)\"}"  https://outlook.webhook.office.com/webhookb2/1cd0c352-6a05-4ac0-9303-ec3ca5fb3716@c4e7a62a-cf18-4a4d-9378-3691521fe44e/IncomingWebhook/a0a83944bfb94bbda6edb7236ff7832b/19cac848-ae46-4f56-898e-599299f87f4a

fi
done </home/user/ip.txt

this was my script

etc/systemd/system/pingtest.service

[Unit]
Description=Ping Test

[Service]
ExecStart=/usr/bin/pingtest.sh
Restart=always
RestartSec=500
[Install]
WantedBy=multi.user.target

Error

root@ping-server:~# systemctl status pingtest.service 
● pingtest.service - Ping Test
   Loaded: loaded (/etc/systemd/system/pingtest.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2022-01-28 07:50:27 UTC; 5min ago
 Main PID: 22006 (code=exited, status=7)
    Tasks: 0 (limit: 1105)
   CGroup: /system.slice/pingtest.service

Jan 28 07:50:27 ping-server systemd[1]: pingtest.service: Main process exited, code=exited, status=7/NOTRUNNING
Jan 28 07:50:27 ping-server systemd[1]: pingtest.service: Failed with result 'exit-code'.   

                     


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source