Syed Jahanzaib – Personal Blog to Share Knowledge !

June 13, 2016

CRON examples ! Focus and save yourself from embarrassment !

Filed under: Linux Related — Tags: , — Syed Jahanzaib / Pinochio~:) @ 3:07 PM

cron examples

 Following commands are made for reference purposes only … zaib


To add scheduled job in linux/ubuntu, use

crontab -e

To view installed cron

crontab -l

Examples:

Run Script after every 5 seconds [Updated 8th Aug, 2016]

I had a UPS monitor script that should run after every 5 seconds to poll the KE input voltage / battery remaining time etc. but as we know that with CRON we can configure interval of minimum 1 minute or above, we cannot set time in seconds. so I make following workaround.

conrtab -e

and added script as follows

# UPMON.SH is my script to monitor UPS
# 10.0.0.1 is my UPS network card
* * * * * /temp/upsmon.sh 10.0.0.1
* * * * * sleep 5; /temp/kemon.sh 10.0.0.1
* * * * * sleep 10; /temp/kemon.sh 10.0.0.1
* * * * * sleep 15; /temp/kemon.sh 10.0.0.1
* * * * * sleep 20; /temp/kemon.sh 10.0.0.1
* * * * * sleep 25; /temp/kemon.sh 10.0.0.1
* * * * * sleep 30; /temp/kemon.sh 10.0.0.1
* * * * * sleep 35; /temp/kemon.sh 10.0.0.1
* * * * * sleep 40; /temp/kemon.sh 10.0.0.1
* * * * * sleep 45; /temp/kemon.sh 10.0.0.1
* * * * * sleep 55; /temp/kemon.sh 10.0.0.1
* * * * * sleep 60; /temp/kemon.sh 10.0.0.1

this way the script will run and wait for five seconds before next execution. 🙂 lalalala / zaib


Run Script after every 2 hours (daily basis* it helped me very much)

0 */2 * * * /temp/script.sh

Run Script at Every 1st day of Month [Every Month]

@monthly /temp/script.sh


Run Script on 1-am on every Monday

0 1 * * MON /temp/xdrive_noupdate.sh


Run Script Daily at 00:00 hours (midnight)

@daily /temp/script.sh

Run Script Daily at 09:00 hours (Morning 9am)

# m h dom mon dow command
00 09 * * * /temp/fullbackup.sh


Run Script every hour 

@hourly /temp/script.sh


Run Script every minute

* * * * * /temp/script.sh


Run Script after every 5 minutes

*/5 * * * * /temp/script.sh


Run Script on Specific Timings And Date of Months, Example run script on 10am and 11am  on 12th of every month.

00 10,11 12 * * /temp/script.sh


Run Script on Specific Hours of Every Month, Example run script on 9am of every month.

00 9 10 * * /temp/script.sh


Run Script on Specific Hours RANGES , Example run script on 10am to 8pm , means every hour from 10am-8pm

00 10-20 * * * /temp/script.sh


Shortcuts in CRON

         
@reboot        Run once, at startup.
@yearly        Run once a year, "0 0 1 1 *".
@annually      (same as @yearly)
@monthly       Run once a month, "0 0 1 * *".
@weekly        Run once a week, "0 0 * * 0".
@daily         Run once a day, "0 0 * * *".
@midnight      (same as @daily)
@hourly        Run once an hour, "0 * * * *".


Scheduled CON Job running but not producing results …

[Monday 27th Feb,2017]

I scheduled few scripts on my Ubuntu 14.x box that queries remote servers for storage and send customized reports via email. I can see its execution in /var/log/syslog but the script was not able to query the remote win server.

To solve it I had to add the PATH command in the script , sample as below…

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

This solved my issue 🙂

These are little things that you learn on daily basis ,

One very useful crontab demonstration to check errors or make cron

https://crontab.guru/


Run script after X minute (just one time only, without using cron)

echo YOUR-SCIPT.SH | at now + 1 minute


Disabling CRON job Emails!

You may want to read this.

https://aacable.wordpress.com/2018/06/08/disabling-email-for-cron-jobs/


Regard’s
Syed Jahanzaib

Sending Email/SMS Alert to User for Service Change Event

Filed under: Radius Manager — Tags: — Syed Jahanzaib / Pinochio~:) @ 12:58 PM

srvchange

 

Screenshot_2016-06-13-12-56-48

SMS Alert


Reference Notes:

Requirements:

We want to send email/sms alert to user about his service package change with old/new package name details. Although this function is builtin in RM , but with customized scripts we can do other functions as well.


Solution:

We will create mysql trigger that will be executed every time srvid column will be changed in rm_users table. then we will create mysql table which will hold all these info. Then the trigger will add user info like old service id , new service id, user name, mobile etc in this table upon srvid change.

Neat & clean.


 

First create mySQL trigger which will be executed once there will be changes made in srvid column in rm_users table.

1- mySQL Trigger

Create file name srvchangetriggers.sql and paste following data

-- MySQL dump 10.13 Distrib 5.5.46, for debian-linux-gnu (i686)
-- Host: localhost Database: radius
-- Syed Jahanzaib
-- ------------------------------------------------------
-- Server version 5.5.46-0ubuntu0.12.04.2-log
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `myTrigger` BEFORE UPDATE ON `rm_users`
FOR EACH ROW BEGIN
IF NEW.srvid <> OLD.srvid THEN
INSERT INTO rm_usersrvchangehistory (datetime, username, newsrvid, oldsrvid, firstname, lastname, mobile) VALUES (NOW(), new.username, new.srvid, old.srvid, new.firstname, new.lastname, new.mobile);
END IF;
END */;;
DELIMITER ;
-- Dumping routines for database 'radius'
--

2- mySQL Table

Add mySQL table where records will be saved.

Create file name rmsrvchangetable.sql and paste following date

-- phpMyAdmin SQL Dump
-- version 3.4.10.1deb1
-- http://www.phpmyadmin.net
-- Syed Jahanzaib
-- Host: localhost
-- Generation Time: Jun 13, 2016 at 10:32 AM
-- Server version: 5.5.46
-- PHP Version: 5.3.10-1ubuntu3.21
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `radius`
--
-- --------------------------------------------------------
--
-- Table structure for table `rm_usersrvchangehistory`
--
CREATE TABLE IF NOT EXISTS `rm_usersrvchangehistory` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`username` varchar(64) NOT NULL,
`newsrvid` varchar(64) NOT NULL,
`oldsrvid` varchar(64) NOT NULL,
`firstname` varchar(64) NOT NULL,
`lastname` varchar(64) NOT NULL,
`mobile` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=63 ;
--
-- Dumping data for table `rm_usersrvchangehistory`
--
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Importing the .sql files in Radius DB / mySQL

Now import both files  in radius DB by command

mysql -uroot -pSQLPASS radius < rmsrvchangetable.sql
mysql -uroot -pSQLPASS radius < srvchangetriggers.sql

Test The Changes …

Now try to change any user service, and check rm_usersrvchangehistory by following command

root@ubuntu:/temp# mysql -u root -pSQLPASS -e "use radius; select * from rm_usersrvchangehistory;"
+----+---------------------+----------+----------+----------+-----------+-----------+-------------+
| id | datetime | username | newsrvid | oldsrvid | firstname | lastname | mobile |
+----+---------------------+----------+----------+----------+-----------+-----------+-------------+
| 71 | 2016-06-13 12:24:00 | test | 4 | 13 | syed | jahanzaib | 03333021909 |
+----+---------------------+----------+----------+----------+-----------+-----------+-------------+

Script to fetch data on scheduled basis and SMS/EMAIL…

Create a script that will be scheduled to run after every 5 minutes , it will check in table rm_usersrvchangehistory and will send sms to user about package change event.

mkdir /temp && cd /temp
touch /temp/srvchange.sh
chmod +x temp/srvchange.sh
nano temp/srvchange.sh

and paste following data…

the Script:

 

#!/bin/bash
# srvchange.sh
# Bash script which will run after every 5 minutes and will fetch info from mysqltable
# and will send SMS/Email alert for service change event.
# Created by SYED JAHANZAIB
# aacable@hotmail.com
# https://aacable.wordpress.com
# Created : 13-JUN-2016
#set -x
SQLUSER="root"
SLQPASS="SQLPASS"

# File where user info wil be hold temporary
TMPUSRINFO=/tmp/usersrvinfo.txt

# Interval in minutes to check user record
INTERVAL="5"

# Fetch user info from the table.
mysql -uroot -p$SQLPASS --skip-column-names -e "use radius; select * from rm_usersrvchangehistory WHERE datetime >= NOW() - INTERVAL $INTERVAL MINUTE;" > $TMPUSRINFO

# KANNEL DETAILS
KHOST="127.0.0.1:13013"
KID="kannel"
KPASS="kannelpass"

# Company Footer
COMPANY="JZ_ISP"

# Apply Count Loop Formula while deleting first line which have junk text
num=0
cat $TMPUSRINFO | while read users
do
num=$[$num+1]
username=`echo $users | awk '{print $4}'`
firstname=`echo $users | awk '{print $7}'`
lastname=`echo $users | awk '{print $8}'`
mobile=`echo $users | awk '{print $9}'`
date=`echo $users | awk '{print $2,$3}'`
newsrvid=`echo $users | awk '{print $5}'`
oldsrvid=`echo $users | awk '{print $6}'`

# Print Info on screen
# Fetch old/new Package Name
OLDPKGNAME=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT srvname FROM radius.rm_services WHERE rm_services.srvid = '$oldsrvid';" |awk 'FNR == 2'`
NEWPKGNAME=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT srvname FROM radius.rm_services WHERE rm_services.srvid = '$newsrvid';" |awk 'FNR == 2'`

# Print FINAL Fetched info
echo "Dear $firstname $lastname ,
Your internet package against your User ID: $username has been upgraded from $OLDPKGNAME to $NEWPKGNAME !

$COMPANY"

# Store Info for sending SMS in /tmp folder where we will call kannel to send customized SMS
echo "Dear $firstname $lastname ,
Your internet package against your User ID: $username has been upgraded from $OLDPKGNAME to $NEWPKGNAME !

$COMPANY" > /tmp/$username.srvchange.sms

# send sms using kannel gateway
curl "http://$KHOST/cgi-bin/sendsms?username=$KID&password=$KPASS&to=$mobile" -G --data-urlencode text@/tmp/$username.srvchange.sms

# If you send lot of SMS via local mobile SIM, then make sure you give enough delay so that your SIM may not get blocked by BULK SMS monitor by TELCOM authority like PTA.
#sleep 15
done
# once done, we should delete the .sms files to clear the garbage
rm -fr /tmp/*.sms


End Results !

Now execute the Script  and witness the Fun !

srvchange


Regard’s
Syed Jahanzaib

KANNEL not responding problem occasionally or after modem reset

Filed under: Linux Related — Tags: , , — Syed Jahanzaib / Pinochio~:) @ 10:22 AM

kannellogo


Scenario:

We have Ubuntu 12.x installed and serial modem is attached (Teltonika G10). Kannel is installed and serving as SMS gateway.

Problem:

Sometimes modem stops responding and when we restart the modem, kannel starts giving error of Routing Failed. After restart of KANNEL service, the kannel starts responding to sms request and works fine.

Requirement:

This little issue can be really annoyed if you are doing remote administration OR if sms alerts are important for you to keep informed about various aspects of the network. We want some automatic mechanism that can detect this specific error and then act accordingly.

Example …

  • If KANNEL service is down , try to start it
  • If failed to start the service, then print error, and sends email about incident, (one email per incident), and exit script
  • If service starts successfully, then print info, and sends email about successful attempt. (one email per incident), and continue further
  • Test Kannel log last entries, and look for word Routing failed, if found, then restart kannel service and email. (one email per incident).
  • If it does not found any entry in LOG for specific word, then Print OK Result for all.

Solution!

 

Disclaimer:

This may or may not work for you. Because I made it for some very particular situation, and this script helped. So this script checks for two things only. 1st kannel service, 2nd kannel log error for routing failed. I am sure this may or may not help you in same situation because its possible that error can be due to something else. I carefully examined my situation and made script for it. You can get some idea by it and modify the script as required.

Schedule Script to run after every 15 minutes or whatever.

Cron Example

# Run KANNEL MONITOR Script after every 15 minutes
*/15 * * * * /temp/kanneltest.sh

 


the SCript !

mkdir /temp
cd /temp
touch /temp/kanneltest.sh
chmod +x /temp/kanneltest.sh
nano /temp/kanneltest.sh

Copy paste following script. Make sure you read it carefully and modify things accordingly.


#!/bin/bash
# No part of this script is copied from anywhere, you are free to use it, modify or distribute.
# Linux BASH script to check KANNEL service Status and internal component system (example kannel service is ok,but not responding to request giving error in logs
# If KANNEL not responding, then send EMail alert to admin (trigger one time for each status changed)
# Useful for remote admins, who want to be informed when KANNEL have any responding problem.
# Created: 9th-JUNE-2016
# Syed Jahanzaib
# aacable at hotmail dot com / https://aacable.wordpress.com
#set -x
# Colors Config . . . [[ JZ . . . ]]
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
# Service name to monitor ...
KANNEL="kannel"
KANNEL_SERVICE_ERROR="kannel_main_service_down"
KANNEL_BEARERBOX="bearerbox"
# Text that will be checked in kannel logs output file,
# So we will simply use the grep to catch word **Routing failed**. You may use other technique that may work for you. Chill / zaib
TEXT_TO_CATCH="Routing failed"
# Hostname and other Variables
HOSTNAME=`hostname`
COMPANY="zaib (Pvt) Ltd."
FOOTER="Powered By Syed.Jahanzaib"
DATE=`date`
# Temporary file holder for KANNEL status
KANNEL_STATUS_TMP_HOLDER="/tmp/KANNELstatus.txt"
KANNEL_SERVICE_TMP_HOLDER="/tmp/kannelservice.txt"
KANNEL_SERVICE_TMP_HOLDER_ERR="/tmp/kannel_servic_error.txt"
KANNEL_QUERY_RESULT="/tmp/KANNEL_query_result.txt"
KANNEL_LOG_FILE="/var/log/kannel/bearerbox.log"
# Create temp file if not already present, usually for 1st time execution
touch $KANNEL_STATUS_TMP_HOLDER
touch $KANNEL_SERVICE_TMP_HOLDER
touch $KANNEL_SERVICE_TMP_HOLDER_ERR
touch $KANNEL_QUERY_RESULT
# EMAIL RELATED and KANNEL INFO
# for down status, we have to use GMAIL to send email
KANNELURL="127.0.0.1:13013"
KANNELID="kannel"
KANNELPASS="KANNELPASS"
CELL1="03333021909"
# GMAIL Section
GMAILID="YOURGMAILID@gmail.com"
GMAILPASS="YOURGMAILPASS"
ADMINMAIL1="aacableAThotmail.com"

###########################################################################################
# Testing KANNEL Service bearerbox status by its PID
echo -e "$COL_RED
Step 1:$COL_RESET INFO: Testing $KANNEL Service status , testing its PID ..."
PID=`pgrep $KANNEL_BEARERBOX`
if [ -n "$PID" ]; then
echo -e "$KANNEL Service Status = $COL_GREEN OK $COL_RESET with pid $PID"
sed -i "/$KANNEL_SERVICE_ERROR/d" "$KANNEL_SERVICE_TMP_HOLDER"
else
echo -e "$COL_RED$KANNEL Service = NOT RUNNING, trying to restarting it ...$COL_RESET"
service $KANNEL stop > /dev/null 2>&1
sleep 5
killall -9 $KANNEL_BEARERBOX > /dev/null 2>&1
sleep 2
service $KANNEL start > /dev/null 2>&1
sleep 5
# IF KANNEL MAIN SERVICE found DOWN, and email/SMS not already sent, then send it one time to $CELL1/x
PID=`pgrep $KANNEL_BEARERBOX`
if [ -z "$PID" ]; then
KSRVAFTRES="DOWN"
echo -e "Script tried to restart $KANNEL MAIN SERVICE and final status is = $COL_RED $KSRVAFTRES $COL_RESET..."
else
KSRVAFTRES="UP/OK"
echo -e "Script tried to restart $KANNEL MAIN SERVICE and final status is = $COL_GREEN $KSRVAFTRES .$COL_RESET..."
if [ $(grep -c "$KANNEL_SERVICE_ERROR" "$KANNEL_SERVICE_TMP_HOLDER") -eq 0 ]; then
echo -e "$COL_RED Sending SMS/EMAIL for KANNEL MAIN SERVICE...$COL_RESET"
PID=`pgrep $KANNEL_BEARERBOX`
if [ -n "$PID" ]; then
KSRVSTATUS="UP/OK"
echo -e "$KANNEL sevice was not running, After script attempt to restart it, its status is $COL_GREEN $KSRVSTATUS $COL_RESET with PID $PID"
KSRVUPMSG="/tmp/ksrvup.msg"
echo "$KANNEL sevice was not running, After script attempt to restart it, its status is $KSRVSTATUS with PID $PID" > $KSRVUPMSG
/temp/sendEmail-v1.56/sendEmail -u "ALERT: $KANNEL service was not working and finally its $KSRVSTATUS @ $DATE" -o tls=yes -s smtp.gmail.com:587 -t $ADMINMAIL1 -xu $GMAILID -xp $GMAILPASS -f $GMAILID -o message-file=$KSRVUPMSG -o message-content-type=text
else
KSRVSTATUS="DOWN"
echo -e "After kannel restart attempt, its status is still $COL_RED $KSRVSTATUS, $COL_RESET... SMS/EMAIL Already sent ..."
#Updating its down log, so script should not repeat sms/email sending
echo "$KANNEL_SERVICE_ERROR" > $KANNEL_SERVICE_TMP_HOLDER
fi
fi
fi
fi

###########################################################################################
# Testing again if above step have started the service or not , if not EXIT the script with the error
# Because if kannel is not running, then checking modem is useless, kannel must be running first in order to proceed further
PID=`pgrep $KANNEL_BEARERBOX`
if [ -n "$PID" ]
then
echo ""
else
echo -e "$COL_REDALERT ALERT: $KANNEL service failed to respond on Service restart request .... please check$COL_RESET
$COL_RED Script cannot continue, exiting ...$COL_RESET"
#exit 0
fi

############## zaib final down
PID=`pgrep $KANNEL_BEARERBOX`
if [ -z "$PID" ]; then
if [ $(grep -c "$KANNEL_SERVICE_ERROR" "$KANNEL_SERVICE_TMP_HOLDER_ERR") -eq 0 ]; then
KSRVSTATUS="DOWN"
KSRVDOWNMSG="/tmp/ksrvdown.msg"
echo "After kannel restart attempt by the script, its status is still $KSRVSTATUS. You need to check it manualy. Now only Human can see what is going on ... "
echo "After kannel restart attempt by the script, its status is still $KSRVSTATUS. You need to check it manualy. Now only Human can see what is going on ... " > $KSRVDOWNMSG
/temp/sendEmail-v1.56/sendEmail -u "ALERT: $KANNEL service failed to restart. Status = $KSRVSTATUS @ $DATE / Check it manualy!" -o tls=yes -s smtp.gmail.com:587 -t $ADMINMAIL1 -xu $GMAILID -xp $GMAILPASS -f $GMAILID -o message-file=$KSRVDOWNMSG -o message-content-type=text
#Updating its down log, so script should not repeat sms/email sending
echo "$KANNEL_SERVICE_ERROR" > $KANNEL_SERVICE_TMP_HOLDER_ERR
exit 0
fi
else
sed -i "/$KANNEL_SERVICE_ERROR/d" "$KANNEL_SERVICE_TMP_HOLDER_ERR"
fi

###########################################################################################
PID=`pgrep $KANNEL_BEARERBOX`
if [ -n "$PID" ]
then
echo ""
else
echo -e "$COL_REDALERT ALERT: $KANNEL service failed to respond on Service restart request .... please check$COL_RESET
$COL_RED Script cannot continue, exiting ...$COL_RESET"
exit 0
fi

###########################################################################################
# Run the script to test kannel internal processing ...
echo -e "$COL_RED
Step 2:$COL_RESET
Testing Kannel internal Service Status in LOGS for internal responding @DATE ..."
for KANNEL in $KANNEL
do
# Match $TEXT_TO_CATCH in the log file grep query result
STATUS=`tail -n 10 $KANNEL_LOG_FILE | grep "$TEXT_TO_CATCH"`
if [ -n "$STATUS" ]; then
# Print Result for information purposes
echo "ALERT: text ** $TEXT_TO_CATCH ** found in $KANNEL_QUERY_RESULT"
echo -e "$COL_RED
$KANNEL service is UP but internal system is not responding to SMS ... Trying to restarting $KANNEL service ...$COL_RESET"
# IF KANNEL found DOWN, and email/SMS not already sent, then send it one time to $CELL1/x
if [ $(grep -c "$KANNEL" "$KANNEL_STATUS_TMP_HOLDER") -eq 0 ]; then
# Restart the KANNEL service
service kannel stop > /dev/null 2>&1
sleep 5
killall -9 bearerbox > /dev/null 2>&1
sleep 2
service kannel start > /dev/null 2>&1
sleep 5
echo -e "$COL_RED
$KANNEL service is UP but internal system is not responding $DATE .. SENDING DOWN SMS/EMAIL for current incident / for one time only ...$COL_RESET"
# Update KANNEL down status in a file so that sms/email should not be sent again and again
echo "$KANNEL" > $KANNEL_STATUS_TMP_HOLDER
# Sending DOWN SMS via KANNEL
echo -e "$COL_REDSending SMS , if KANNEL SERVICE is down or internal system not responding, SMS will NOT be sent ...$COL_RESET
"
# Update down message to be sent via sms/email
echo "$MSG_DOWN" > $MSGDOWNHOLDER
# sen email using sendemail tool
cat $MSGDOWNHOLDER | curl "http://$KANNELURL/cgi-bin/sendsms?username=$KANNELID&password=$KANNELPASS&to=$CELL1" -G --data-urlencode text@-
######## EMAIL SECTION ##############
# Make sure you install sendEMAIL tool and test it properly before using email section.
#SEND EMAIL Alert As well using sendEMAIL tool using GMAIL ADDRESS.
# If you want to send email , use below ...
echo -e "$COL_REDSending EMAIL ALERT to $ADMINMAIL1 ...$COL_RESET
"
/temp/sendEmail-v1.56/sendEmail -u "ALERT: $KANNEL not responding @ $DATE" -o tls=yes -s smtp.gmail.com:587 -t $ADMINMAIL1 -xu $GMAILID -xp $GMAILPASS -f $GMAILID -o message-file=$MSGDOWNHOLDER -o message-content-type=text
fi

###########################################################################################
# Else if $TEXT_TO_CATCH does not found in $KANNEL_QUERY_RESULT, then consider KANNEL is UP
else
echo -e "$COL_GREEN
INFO:$COL_RESET Word ** $TEXT_TO_CATCH ** was NOT found in $KANNEL_LOG_FILE
$COL_RED
FINAL RESULT:$COL_RESET
$KANNEL service = $COL_GREEN OK $COL_RESET
$KANNEL iternal system = $COL_GREEN OK $COL_RESET / All seems to be responding OK!
"
# If KANNEL found UP and last status was DOWN, then send UP msg one time
if [ $(grep -c "$KANNEL" "$KANNEL_STATUS_TMP_HOLDER") -eq 1 ]; then
echo "$KANNEL internal system is now responding at $(date)... SENDING UP SMS for current incident one time only ...
"
echo "$MSG_UP" > $MSGUPHOLDER
# Sending UP SMS via KANNEL
echo -e "Sending $COL_GREENUP$COL_RESET SMS , if KANNEL process is down, sms will not be sent ...
"
cat $MSGUPHOLDER | curl "http://$KANNELURL/cgi-bin/sendsms?username=$KANNELID&password=$KANNELPASS&to=$CELL1" -G --data-urlencode text@-
############## EMAIL SECTION ##############
# Make sure you install sendEMAIL tool and test it properly before using email section.
#SEND EMAIL Alert As well using sendEMAIL tool using GMAIL ADDRESS.
# If you want to send email , use below ...
echo "Sending SEMAIL UP/OK to $ADMINMAIL1 & $ADMINMAIL2 ...
"
/temp/sendEmail-v1.56/sendEmail -u "INFO: $KANNEL internal system is now responding OK @ $DATE" -o tls=yes -s smtp.gmail.com:587 -t $ADMINMAIL1 -xu $GMAILID -xp $GMAILPASS -f $GMAILID -o message-file=$MSGDOWNHOLDER -o message-content-type=text
# Update KANNEL UP status in a file so that sms/email should not be sent again and again
sed -i "/$KANNEL/d" "$KANNEL_STATUS_TMP_HOLDER"
fi
fi
done
# Script Ends Here ...
# z@iB


Script Results:

1- script execute result

 

1- srv down and restarted ok up result

 

1- srv down failed to restart

1-upndown

3 -intok


Regard’s
Syed Jahanzaib