[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.
If your server was not showing the correct date then something could be wrong with your server or its internet connection or how ntp is configured.
Code:
while read var value
do
"$var"= curl -XPUT 'http://google.com-'$date'
done
You have many syntax errors with your loop. And while we could fix the errors if the server and ntp is configured and running correctly you should not have a date problem.
@1s440: can you please change your thread title (currently: "Script") into something much more specific? (HOWTO: select a new title by editing your thread original post)
@1s440: can you please change your thread title (currently: "Script") into something much more specific? (HOWTO: select a new title by editing your thread original post)
This is very useful, but the curly braces in the sed command are a bit too baroque for my taste. What’s wrong with
Code:
sed -n ‘/^Date/s/Date: //p’
?
I didn't know about the p flag in substitution command, thank you!
Actually, this doesn't change anything in this simple example. So well done
But braces are still required for more advanced use-cases when you need to nest instructions in relation to a /pattern/...
This is very useful, but the curly braces in the sed command are a bit too baroque for my taste. What’s wrong with
Code:
sed -n ‘/^Date/s/Date: //p’
?
And I refuse to learn Perl.
Code:
#!/bin/bash
date
VAR=$(curl -i http://google.com/ | grep Date)
echo "Today date is "$date""
echo "Output is "$VAR""
if [ $VAR -eq $date ]; then
echo "date is correct"
else
echo "date is wrong"
fi
#!/bin/bash
date
VAR=$(curl -i http://google.com/ | grep Date)
echo "Today date is "$date""
echo "Output is "$VAR""
if [ $VAR -eq $date ]; then
echo "date is correct"
else
echo "date is wrong"
fi
-eq is a numerical comparison so you need surrounding double parentheses ((. But I don't think it's gonna work because date returns a string... So you may want [[ $VAR == $date ]] instead (if I were you I would prefer using double square brackets ([[) instead of single bracket command ([) in your bash scripts).
Where is your date variable initialized?
What makes you think it answers berndbausch's question?
And finally, please use [CODE] tags.
A direct comparison of the two variables will never be the same.
The header is in UTC(GMT) so you need to use the date -u command. In addition time will never match and the format is different. Are you trying to verify the day, time or both?
If you are writing a bash script, then if I were you I would prefer using double square brackets ([[) instead of single bracket command ([).
Where is date variable initialized?
What makes you think it answers berndbausch's question?
And finally, please use [CODE] tags.
Hi Ignore the previous here is the correct but facing problems with sed
Code:
#!/bin/bash
date
VAR=$(curl -i http://google.com/ | grep Date | sed ‘s/Date: //‘ )
echo "´Today date is $(date)´"
echo "Output is $VAR"
if [[ $VAR -eq $(date) ]]; then
echo "´correct´"
else
echo "´wrong´"
fi
")syntax error in expression (error token is ": Wed, 28 Nov 2018 15:35:29 GMT
´wrong´
Hi Ignore the previous here is the correct but facing problems with sed
#!/bin/bash
date
VAR=$(curl -i http://google.com/ | grep Date | sed ‘s/Date: //‘ )
echo "´Today date is $(date)´"
echo "Output is $VAR"
if [[ $VAR -eq $(date) ]]; then
echo "´correct´"
else
echo "´wrong´"
fi
")syntax error in expression (error token is ": Wed, 28 Nov 2018 15:35:29 GMT
´wrong´
Please see my previous (edited) post (your problem is not sed related but it's about -eq instruction inside double brackets).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.