[SOLVED] Synchronization of date between server and apache webserver, grep and sed instructions.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The date command -u option (date -u "+%H") displays the hours as UTC which is the same as GMT which should match the header time. In your code your forgot the "$" in your if statement variables and you should use [[ instead of ((.
Code:
if [[ $Date == $VAR ]]; then
echo "Hours match"
else
echo "Hours not match"
fi
Code:
#!/bin/bash
wtime=$(curl -i http://google.com/ 2>/dev/null | grep Date | sed 's/Date: //')
t3=$(cut -d' ' -f5 <<< "$wtime")
hr=$(cut -d':' -f1 <<< "$t3")
ltime=$(date -u "+%H:%M:%S")
lhr=$(date -u "+%H")
echo "Web Server time=$t3, Server time=$ltime"
if [[ $lhr == $hr ]]; then
echo "Hours match"
else
echo "Hours not match"
fi
I've added additional output to display the web server HTML header time and your server time as a visual display.
hmm. this works. Thanks a lot but with GMT timings.
Oops, in addition to what I posted above since the VAR is basically a string that contains a line feed character using (( )) in your if statement fails.
Quote:
Thanks a lot but with GMT timings.
Not quite. The linux system clock is referenced to UTC (GMT) and it is the timezone setting that converts it to local time that is displayed on the desktop and via the date command.
on the nagios monitoring it shows me the wrong output
Quote:
user@nagios:/usr/local/nagios/plugins# ./check_date.sh -H www.myserver.com
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 980 100 980 0 0 20736 0 --:--:-- --:--:-- --:--:-- 20851
Today date is we, 19 Dec 2018
Output is
Date is wrong
^ Please provide us with check_date.sh script content
But on the server it displays correct when i use it on the nagios and check it shows me wrong. confused
Code:
#!/bin/bash
myDate=$(date "+%a, %d %b %Y")
VAR=$(curl -i http://myserver.com/sample.htm | sed -n '/Date/s/Date: //p')
echo "Today date is $myDate"
echo "Output is $VAR"
if [[ ${VAR%% [[:digit:]][[:digit:]]:*} == $myDate ]]; then
echo "Date is correct"
else
echo "Date is wrong"
fi
In check_date.sh, did you replace the following bogus instruction?
Code:
curl -i http://myserver.com/sample.htm
Plus, why are you using switch -H when you are calling your script? And why are you specifying a parameter as your script doesn't deal with any (the URL is hard-coded inside the script itself)?
In check_date.sh, did you replace the following bogus instruction?
Code:
curl -i http://myserver.com/sample.htm
Plus, why are you using switch -H when you are calling your script? And why are you specifying a parameter as your script doesn't deal with any (the URL is hard-coded inside the script itself)?
Hi I wanted to run a script on the host from nagios server thats why i am specifiying hostname where the script should be tested. I placed my script under /usr/local/nagios/plugins/ and executing on hostname www.myserver.com with the help of -H
$VAR is empty. I assume you are using the same website as previously? Is the format different i.e sed is failing to find the string Date:? Running from the nagios server isn't working the same.
$VAR is empty. I assume you are using the same website as previously? Is the format different i.e sed is failing to find the string Date:? Running from the nagios server isn't working the same.
yes the output is empty, I am using the same website.
sorry seems my fault the script is placed on nagios plugins not on the host plugins. i think i should add service config
the script you posted does not accept -H <server> arguments, therefore hard to say anything.
From the other hand you need to save stderr and check if there was anything in it. This would be the best place to find the reason.
the script you posted does not accept -H <server> arguments, therefore hard to say anything.
From the other hand you need to save stderr and check if there was anything in it. This would be the best place to find the reason.
Hi modified the script curl command and now i am able to match.
Quote:
curl -v --silent "http://myserver.com/sample.htm/" 2>/dev/null \ | grep Date | sed -e 's/< Date: //'); date "+%a, %d %b %Y"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.