LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 11-27-2018, 04:42 AM   #1
1s440
Member
 
Registered: Mar 2018
Posts: 266

Rep: Reputation: Disabled
Synchronization of date between server and apache webserver, grep and sed instructions.


Hello all,

I wanted to check the date from the URL and here is my script below. Please let me know if its correct
Code:
date=`date +%Y-%m-%d`;
URL="http://google.com-$date";
while read var value
do
    "$var"= curl -XPUT 'http://google.com-'$date'
done

Last edited by 1s440; 11-29-2018 at 05:06 AM.
 
Old 11-27-2018, 05:17 AM   #2
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
If you want to verify/debug your script, maybe you could start by displaying variables progressively so you see as soon as a problem arises
You can also add
Code:
set -xv
at the beginning

Last edited by l0f4r0; 11-27-2018 at 05:19 AM.
 
2 members found this post helpful.
Old 11-27-2018, 06:04 AM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by 1s440 View Post
Hello all,

I wanted to check the date from the URL and here is my script below. Please let me know if its correct

date=`date +%Y-%m-%d`;
URL="http://google.com-$date";
while read var value
do
"$var"= curl -XPUT 'http://google.com-'$date'
done
I don’t understand what the script is supposed to do, but here are a few comments.
  1. You never use variable URL. You can get rid of it.
  2. You never use variable value. You can get rid of it.
  3. You read var, then try to assign something to var. This is not illegal but doesn’t make sense.
  4. To assign something to var, don’t use the dollar or quote signs.
  5. To assign the output of the curl command to var, use var=$(curl ....)
  6. Toassign the return value of the curl command, run the curl command, then immediately var=$!.
  7. Putting single quotes around $date has the effect that the date variable is not evaluated. Instead, the value of this expression is a literal $date.
  8. There is an unclosed quote character in the curl command.

Last edited by berndbausch; 11-27-2018 at 06:11 AM.
 
Old 11-27-2018, 06:34 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
this hopefully will give you some insight on this.

https://stackoverflow.com/questions/...g-shell-script
 
Old 11-27-2018, 06:48 AM   #5
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
I don’t understand what the script is supposed to do, but here are a few comments.
  1. You never use variable URL. You can get rid of it.
  2. You never use variable value. You can get rid of it.
  3. You read var, then try to assign something to var. This is not illegal but doesn’t make sense.
  4. To assign something to var, don’t use the dollar or quote signs.
  5. To assign the output of the curl command to var, use var=$(curl ....)
  6. Toassign the return value of the curl command, run the curl command, then immediately var=$!.
  7. Putting single quotes around $date has the effect that the date variable is not evaluated. Instead, the value of this expression is a literal $date.
  8. There is an unclosed quote character in the curl command.
Thanks for the reply. Curl doesnot show the date from the url, would wget is the best option to fetch data from URL? The date varies everyday.

Last edited by 1s440; 11-27-2018 at 07:04 AM. Reason: modifying
 
Old 11-27-2018, 07:35 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
I would suggest you to use www.shellcheck.net to check your script.

Quote:
Originally Posted by 1s440 View Post
Thanks for the reply. Curl doesnot show the date from the url, would wget is the best option to fetch data from URL? The date varies everyday.
Would be nice to explain what did you try, what's happened and what do you want to achieve.

I don't think this is valid: http://google.com-'$date'
 
Old 11-27-2018, 08:05 AM   #7
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
I would suggest you to use www.shellcheck.net to check your script.



Would be nice to explain what did you try, what's happened and what do you want to achieve.

I don't think this is valid: http://google.com-'$date'
Hi,

Thanks for the reply. I am trying to fetch the current date from URL ex: http://www.google.com/ and I would like to do a script such that if the URL doesnot display the current date then there should be an error.
 
Old 11-27-2018, 08:07 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
Sorry, but I do not understand. What do you mean by "to fetch the current date from URL"? URL usually does not contain date.
see for example: https://www.linuxquestions.org/quest...pt-4175643169/
 
Old 11-27-2018, 08:21 AM   #9
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by 1s440 View Post
Thanks for the reply. Curl doesnot show the date from the url, would wget is the best option to fetch data from URL? The date varies everyday.
I don’t know how to show the current date using Google. However, you can show thw current date with the date command.
 
Old 11-27-2018, 08:23 AM   #10
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
I don’t know how to show the current date using Google. However, you can show thw current date with the date command.
yes with date command its possible but when i want to check for a website then its complicated
 
Old 11-27-2018, 08:34 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
so what do you want to check?
 
1 members found this post helpful.
Old 11-27-2018, 08:39 AM   #12
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
^ +1. Yes, please be specific. It will prevent misunderstandings (hence inappropriate advice) from happening.
 
Old 11-28-2018, 02:27 AM   #13
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Hi we have configured apache such that when you browse the web server you see a welcome date for example if you have logged in today it shows today date. but I need to implement a monitoring check for this. whenever you login via the apache webserver you see a date if you login tomorrow it shows tommorrow date. last week I had a issue with that where it was not updating the current date. so I am trying now to implement a check. So I thought once I develop a script it would be easy to create monitoring check.
 
Old 11-28-2018, 03:35 AM   #14
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by 1s440 View Post
Hi we have configured apache such that when you browse the web server you see a welcome date for example if you have logged in today it shows today date. but I need to implement a monitoring check for this. whenever you login via the apache webserver you see a date if you login tomorrow it shows tommorrow date. last week I had a issue with that where it was not updating the current date. so I am trying now to implement a check. So I thought once I develop a script it would be easy to create monitoring check.
So you don't trust the date command, and you want to use Google's date instead? If you explain to me how to show the current date with Google, we can help with your script.

It's probably better to fix your time management though. Ensure NTP is configured correctly and that you have access to one or more working NTP servers.
 
Old 11-28-2018, 03:53 AM   #15
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
So you don't trust the date command, and you want to use Google's date instead? If you explain to me how to show the current date with Google, we can help with your script.

It's probably better to fix your time management though. Ensure NTP is configured correctly and that you have access to one or more working NTP servers.
Hi I took google as an example, As said we use date command on the server to get the current date but when you wanted to develop some monitoring checks its complicated and doesnot work.when I try to execute the script i am getting errors. Ofcourse NTP is configured correctly

Last edited by 1s440; 11-28-2018 at 03:57 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
can't run a script script from icon in konqueror scottsteibel Linux - Software 1 08-02-2003 07:59 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM
E-Mail notification to users via SMS (gateway script ok, but notification script?!?) Riku2015 Linux - Networking 10 03-08-2002 10:16 AM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 05:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration