Monitor Linux host system time consistency

Source: Internet
Author: User

#!/bin/bash
State_ok=0
State_warning=1
state_critical=2
State_unknown=3
Passwd= ' ************** '
Print_help () {
echo "Usage:"
echo "-h)"
echo "Host Address"
echo "[-W] Warning"
echo "[-c] Critical"
Exit $STATE _OK
}
While Test-n "$"; Do
Case "$" in
--HELP|-H)
Print_help
Exit $STATE _OK
;;
--URL|-H)
Hostaddress=$2
Shift
;;
-W)
Warn_level=$2
Shift
;;
-c)
Critical_level=$2
Shift
;;
*)
echo "Unknown Argument: $ $"
Print_help
Exit $STATE _unknown
;;
Esac
Shift
Done
If ["$warn _level" = = ""]; Then
echo "No Warning level Specified"
Print_help
Exit $STATE _unknown;
Fi
If ["$critical _level" = = ""]; Then
echo "No Critical level Specified"
Print_help
Exit $STATE _unknown;
Fi
If ["$HOSTADDRESS" = = ""]; Then
echo "No hostaddress Specified"
Print_help
Exit $STATE _unknown;
Fi
echo "" >/usr/local/nagios/libexec/check_time_data/host_time_$hostaddress
/usr/local/bin/expect <<eof
Log_file/usr/local/nagios/libexec/check_time_data/host_time_$hostaddress
Log_user 1
Spawn Ssh-t-P 22[email protected]$HOSTADDRESS "Date +%s"
Expect {
"(yes/no)?"
{

Send "yes\r"
Expect "*assword" {send "$PASSWD \ r"}

}
"*assword" {

Send "$PASSWD \ r"
}

}
Expect "100%"
Eof
# # #处理数据格式
Sed-i ' s/\r//g '/usr/local/nagios/libexec/check_time_data/host_time_$hostaddress

# # #处理时间


Host_time= ' cat/usr/local/nagios/libexec/check_time_data/host_time_$hostaddress|grep-e ' ^[0-9] '


Cur_time= ' Date +%s '

Value= ' expr $cur _time-$host _time '

If [$value-lt 0]; Then
Let value=0-$value;
Fi


if [["$value"-le "$warn _level"]]; Then
echo "$HOSTADDRESS time is OK. $HOSTADDRESS _time-cur_time: $value |value= $value; $warn _level; $critical _level;0 "
Exit $STATE _OK;
elif [["$value"-GT "$warn _level"]] && [["$value"-lt "$critical _level"]; Then
echo "$HOSTADDRESS time is WARNING. $HOSTADDRESS _time-cur_time: $value |value= $value; $warn _level; $critical _level;0 "
Exit $STATE _warning;
elif [["$value"-ge "$critical _level"]]; Then
echo "$HOSTADDRESS time is CRITICAL. $HOSTADDRESS _time-cur_time: $value |value= $value; $warn _level; $critical _level;0 "
Exit $STATE _critical;
Fi

Monitor Linux host system time consistency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.