- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: crontab to send alert only once
Operating System - HP-UX
1752265
Members
4869
Online
108786
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2010 07:44 AM
тАО05-14-2010 07:44 AM
Re: crontab to send alert only once
Add a date tag to your flag file name like "touch /tmp/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2010 08:37 AM
тАО05-14-2010 08:37 AM
Re: crontab to send alert only once
You could also use current epoch and if the diff between the last alert and current alert are > 86400 secs, clear your lock file and send another alert.
To get the epoch with perl...
perl -e 'print time'
If you're comfortable with perl, write your alert script in perl... if not, then write it in shell and use the perl to set a variable.
here's an example to get you started... you can put this into a function which gets called when your alert condition exists. If the lapse between the current alert and last alert are > 86400 second (24hrs) it can send another alert.
-----
typeset -i ALERTED NOW DIFF LAPSE
LOCK=/tmp/mylock.file # your lock file
LAPSE=86400 # min seconds between alerts
NOW=$(perl -e 'print time')
ALERTED=$(cat ${LOCK} 2>/dev/null)
# diff between last alert time and now
DIFF=$((NOW - ALERTED))
if [ ${DIFF} -gt ${LAPSE} ];then
# send your alert and update lock file
commands to send your alert
echo ${NOW} > ${LOCK}
fi
-----
Hope this helps,
-denver
To get the epoch with perl...
perl -e 'print time'
If you're comfortable with perl, write your alert script in perl... if not, then write it in shell and use the perl to set a variable.
here's an example to get you started... you can put this into a function which gets called when your alert condition exists. If the lapse between the current alert and last alert are > 86400 second (24hrs) it can send another alert.
-----
typeset -i ALERTED NOW DIFF LAPSE
LOCK=/tmp/mylock.file # your lock file
LAPSE=86400 # min seconds between alerts
NOW=$(perl -e 'print time')
ALERTED=$(cat ${LOCK} 2>/dev/null)
# diff between last alert time and now
DIFF=$((NOW - ALERTED))
if [ ${DIFF} -gt ${LAPSE} ];then
# send your alert and update lock file
commands to send your alert
echo ${NOW} > ${LOCK}
fi
-----
Hope this helps,
-denver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2010 11:46 PM
тАО05-15-2010 11:46 PM
Re: crontab to send alert only once
Hi Steve , Steven , TTr , Raynald and Denver ,
Many thanks for the input ,here's how i am able to manage it as of now,
====================
a=`cat /tmp/value1`
when=`date | cut -c 5-16`
echo $when
echo $a
b=`/usr/local/bin/lsof -i tcp:21414 | grep -v "^COMMAND"| wc -l`
if [ "$a" -lt "$b" ]
then
c=`expr $b - $a`
echo $c
mailx -s"Number of process on 192.168.83.2:21414 has been increased by $c at $when " mathewsml@infinity.hcl.com < /dev/null
a=$b
echo $a > /tmp/value1
elif [ "$a" -gt "$b" ];then
d=`expr $a - $b`
mailx -s"Number of process on 192.168.83.2:21414 has been decreased by $d at $when " mathewsml@infinity.hcl.com < /dev/null
echo $b > /tmp/value1
elif [ "$a" -eq "$b" ]
then
echo $b > /tmp/value1
fi
Many thanks for the input ,here's how i am able to manage it as of now,
====================
a=`cat /tmp/value1`
when=`date | cut -c 5-16`
echo $when
echo $a
b=`/usr/local/bin/lsof -i tcp:21414 | grep -v "^COMMAND"| wc -l`
if [ "$a" -lt "$b" ]
then
c=`expr $b - $a`
echo $c
mailx -s"Number of process on 192.168.83.2:21414 has been increased by $c at $when " mathewsml@infinity.hcl.com < /dev/null
a=$b
echo $a > /tmp/value1
elif [ "$a" -gt "$b" ];then
d=`expr $a - $b`
mailx -s"Number of process on 192.168.83.2:21414 has been decreased by $d at $when " mathewsml@infinity.hcl.com < /dev/null
echo $b > /tmp/value1
elif [ "$a" -eq "$b" ]
then
echo $b > /tmp/value1
fi
FrogIsDeaf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2010 04:32 AM
тАО05-17-2010 04:32 AM
Re: crontab to send alert only once
I assume you know this. But maybe not? So here you go.
Here is the $when line rewritten.
when=$(date +"%b %d %H:%M")
I'm only worried about May being a 3 digit month vs 4 digits for June. The %b will give you a 3 digit month.
You could redo it to 17May2010_08:30
when=$(date +"%d%b%Y_%H:%M")
Now even though I picking on a line of your code, It's great. I'd already copied it.
Steve
Here is the $when line rewritten.
when=$(date +"%b %d %H:%M")
I'm only worried about May being a 3 digit month vs 4 digits for June. The %b will give you a 3 digit month.
You could redo it to 17May2010_08:30
when=$(date +"%d%b%Y_%H:%M")
Now even though I picking on a line of your code, It's great. I'd already copied it.
Steve
- « Previous
-
- 1
- 2
- Next »
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP