Set date and time from http header in router with curl or wget
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
1
down vote
favorite
This technique should be similar or the same as on Ubuntu; though the following code does not work on the router. One method is the following:
dateFromServer=$(curl -v --silent https://google.com/ 2>&1
| grep Date | sed -e 's/< Date: //')
date +"%d%m%Y%H%M%S" -d "$dateFromServer"
The result is
'ate: invalid date 'Sat, 12 May 2018 18:49:18 GMT
or Get the date from a HTTP response header. Remove clutter. Set the date.
date -s `curl -I 'https://startpage.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'`
The results I get are as follows:
@Heyzeus:/tmp/home/root# date -s `curl -I 'https://google.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'` BusyBox v1.25.1 (2018-05-06 13:19:15 EDT) multi-call binary.
Usage: date [OPTIONS] [+FMT] [TIME]
Display time (using +FMT), or set time
[-s,--set] TIME Set time to TIME
-u,--utc Work in UTC (don't convert to local time)
-R,--rfc-2822 Output RFC-2822 compliant date string
-I[SPEC] Output ISO-8601 compliant date string SPEC='date' (default) for date only, 'hours', 'minutes', or 'seconds' for date and time to the indicated precision
-r,--reference FILE Display last modification time of FILE
-d,--date TIME Display TIME, not 'now'
-D FMT Use FMT for -d TIME conversion
Recognized TIME formats: hh:mm[:ss] [YYYY.]MM.DD-hh:mm[:ss] YYYY-MM-DD hh:mm[:ss] [[[[[YY]YY]MM]DD]hh]mm[.ss] 'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
Another
date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date:
| cut -d' ' -f5-8)"
results in: date: invalid date '13 May 2018 22:46:44'
The time extrated the first two results is for example:
"Sat, 12 May 2018 18:49:18 GMT"
and date -s requires something more like
2018-05-12 18:49:18
Or as listed under "recognized time formats."
Its close. But "Sat," needs to be removed, month needs replacing with a number, and then arranged properly; If this could be done exclusively in a single terminal command that would be great.
command-line bash time sed dd
add a comment |Â
up vote
1
down vote
favorite
This technique should be similar or the same as on Ubuntu; though the following code does not work on the router. One method is the following:
dateFromServer=$(curl -v --silent https://google.com/ 2>&1
| grep Date | sed -e 's/< Date: //')
date +"%d%m%Y%H%M%S" -d "$dateFromServer"
The result is
'ate: invalid date 'Sat, 12 May 2018 18:49:18 GMT
or Get the date from a HTTP response header. Remove clutter. Set the date.
date -s `curl -I 'https://startpage.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'`
The results I get are as follows:
@Heyzeus:/tmp/home/root# date -s `curl -I 'https://google.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'` BusyBox v1.25.1 (2018-05-06 13:19:15 EDT) multi-call binary.
Usage: date [OPTIONS] [+FMT] [TIME]
Display time (using +FMT), or set time
[-s,--set] TIME Set time to TIME
-u,--utc Work in UTC (don't convert to local time)
-R,--rfc-2822 Output RFC-2822 compliant date string
-I[SPEC] Output ISO-8601 compliant date string SPEC='date' (default) for date only, 'hours', 'minutes', or 'seconds' for date and time to the indicated precision
-r,--reference FILE Display last modification time of FILE
-d,--date TIME Display TIME, not 'now'
-D FMT Use FMT for -d TIME conversion
Recognized TIME formats: hh:mm[:ss] [YYYY.]MM.DD-hh:mm[:ss] YYYY-MM-DD hh:mm[:ss] [[[[[YY]YY]MM]DD]hh]mm[.ss] 'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
Another
date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date:
| cut -d' ' -f5-8)"
results in: date: invalid date '13 May 2018 22:46:44'
The time extrated the first two results is for example:
"Sat, 12 May 2018 18:49:18 GMT"
and date -s requires something more like
2018-05-12 18:49:18
Or as listed under "recognized time formats."
Its close. But "Sat," needs to be removed, month needs replacing with a number, and then arranged properly; If this could be done exclusively in a single terminal command that would be great.
command-line bash time sed dd
The last error message seems to be mangled, could you please edit and correct it?
â dessert
May 13 at 6:32
1
Possible duplicate of What is the command to update time and date from internet - Please review the second answer that is identical as your approach.
â pa4080
May 13 at 7:00
@dessert, updated! @Heyzeus/tmp/home/root# date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z " results in: date: invalid date '13 May 2018 22:46:44Z'. date -s requires something more like 2018-05-12 2018 18:49:18
â Tyler
May 13 at 22:47
or rather: date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)" results in: date: invalid date '13 May 2018 22:46:44'
â Tyler
May 13 at 22:53
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
This technique should be similar or the same as on Ubuntu; though the following code does not work on the router. One method is the following:
dateFromServer=$(curl -v --silent https://google.com/ 2>&1
| grep Date | sed -e 's/< Date: //')
date +"%d%m%Y%H%M%S" -d "$dateFromServer"
The result is
'ate: invalid date 'Sat, 12 May 2018 18:49:18 GMT
or Get the date from a HTTP response header. Remove clutter. Set the date.
date -s `curl -I 'https://startpage.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'`
The results I get are as follows:
@Heyzeus:/tmp/home/root# date -s `curl -I 'https://google.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'` BusyBox v1.25.1 (2018-05-06 13:19:15 EDT) multi-call binary.
Usage: date [OPTIONS] [+FMT] [TIME]
Display time (using +FMT), or set time
[-s,--set] TIME Set time to TIME
-u,--utc Work in UTC (don't convert to local time)
-R,--rfc-2822 Output RFC-2822 compliant date string
-I[SPEC] Output ISO-8601 compliant date string SPEC='date' (default) for date only, 'hours', 'minutes', or 'seconds' for date and time to the indicated precision
-r,--reference FILE Display last modification time of FILE
-d,--date TIME Display TIME, not 'now'
-D FMT Use FMT for -d TIME conversion
Recognized TIME formats: hh:mm[:ss] [YYYY.]MM.DD-hh:mm[:ss] YYYY-MM-DD hh:mm[:ss] [[[[[YY]YY]MM]DD]hh]mm[.ss] 'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
Another
date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date:
| cut -d' ' -f5-8)"
results in: date: invalid date '13 May 2018 22:46:44'
The time extrated the first two results is for example:
"Sat, 12 May 2018 18:49:18 GMT"
and date -s requires something more like
2018-05-12 18:49:18
Or as listed under "recognized time formats."
Its close. But "Sat," needs to be removed, month needs replacing with a number, and then arranged properly; If this could be done exclusively in a single terminal command that would be great.
command-line bash time sed dd
This technique should be similar or the same as on Ubuntu; though the following code does not work on the router. One method is the following:
dateFromServer=$(curl -v --silent https://google.com/ 2>&1
| grep Date | sed -e 's/< Date: //')
date +"%d%m%Y%H%M%S" -d "$dateFromServer"
The result is
'ate: invalid date 'Sat, 12 May 2018 18:49:18 GMT
or Get the date from a HTTP response header. Remove clutter. Set the date.
date -s `curl -I 'https://startpage.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'`
The results I get are as follows:
@Heyzeus:/tmp/home/root# date -s `curl -I 'https://google.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'` BusyBox v1.25.1 (2018-05-06 13:19:15 EDT) multi-call binary.
Usage: date [OPTIONS] [+FMT] [TIME]
Display time (using +FMT), or set time
[-s,--set] TIME Set time to TIME
-u,--utc Work in UTC (don't convert to local time)
-R,--rfc-2822 Output RFC-2822 compliant date string
-I[SPEC] Output ISO-8601 compliant date string SPEC='date' (default) for date only, 'hours', 'minutes', or 'seconds' for date and time to the indicated precision
-r,--reference FILE Display last modification time of FILE
-d,--date TIME Display TIME, not 'now'
-D FMT Use FMT for -d TIME conversion
Recognized TIME formats: hh:mm[:ss] [YYYY.]MM.DD-hh:mm[:ss] YYYY-MM-DD hh:mm[:ss] [[[[[YY]YY]MM]DD]hh]mm[.ss] 'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
Another
date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date:
| cut -d' ' -f5-8)"
results in: date: invalid date '13 May 2018 22:46:44'
The time extrated the first two results is for example:
"Sat, 12 May 2018 18:49:18 GMT"
and date -s requires something more like
2018-05-12 18:49:18
Or as listed under "recognized time formats."
Its close. But "Sat," needs to be removed, month needs replacing with a number, and then arranged properly; If this could be done exclusively in a single terminal command that would be great.
command-line bash time sed dd
edited May 13 at 22:55
asked May 13 at 0:07
Tyler
264
264
The last error message seems to be mangled, could you please edit and correct it?
â dessert
May 13 at 6:32
1
Possible duplicate of What is the command to update time and date from internet - Please review the second answer that is identical as your approach.
â pa4080
May 13 at 7:00
@dessert, updated! @Heyzeus/tmp/home/root# date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z " results in: date: invalid date '13 May 2018 22:46:44Z'. date -s requires something more like 2018-05-12 2018 18:49:18
â Tyler
May 13 at 22:47
or rather: date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)" results in: date: invalid date '13 May 2018 22:46:44'
â Tyler
May 13 at 22:53
add a comment |Â
The last error message seems to be mangled, could you please edit and correct it?
â dessert
May 13 at 6:32
1
Possible duplicate of What is the command to update time and date from internet - Please review the second answer that is identical as your approach.
â pa4080
May 13 at 7:00
@dessert, updated! @Heyzeus/tmp/home/root# date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z " results in: date: invalid date '13 May 2018 22:46:44Z'. date -s requires something more like 2018-05-12 2018 18:49:18
â Tyler
May 13 at 22:47
or rather: date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)" results in: date: invalid date '13 May 2018 22:46:44'
â Tyler
May 13 at 22:53
The last error message seems to be mangled, could you please edit and correct it?
â dessert
May 13 at 6:32
The last error message seems to be mangled, could you please edit and correct it?
â dessert
May 13 at 6:32
1
1
Possible duplicate of What is the command to update time and date from internet - Please review the second answer that is identical as your approach.
â pa4080
May 13 at 7:00
Possible duplicate of What is the command to update time and date from internet - Please review the second answer that is identical as your approach.
â pa4080
May 13 at 7:00
@dessert, updated! @Heyzeus/tmp/home/root# date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z " results in: date: invalid date '13 May 2018 22:46:44Z'. date -s requires something more like 2018-05-12 2018 18:49:18
â Tyler
May 13 at 22:47
@dessert, updated! @Heyzeus/tmp/home/root# date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z " results in: date: invalid date '13 May 2018 22:46:44Z'. date -s requires something more like 2018-05-12 2018 18:49:18
â Tyler
May 13 at 22:47
or rather: date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)" results in: date: invalid date '13 May 2018 22:46:44'
â Tyler
May 13 at 22:53
or rather: date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)" results in: date: invalid date '13 May 2018 22:46:44'
â Tyler
May 13 at 22:53
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
Thanks to Twiglets
Here is an alternative that DOES set the date !!! [-s option].
Prints out 'Date' it retrieves & the 'Date' that is set for comparison.
This works on the AsusWRT / Merlin, the only thing that is odd is that the date retrieved is ".... GMT" and the date utility sets the correct time but changes it to "... DST"
Environment has TZ set to "GMT"
datetext=$(curl -I 'https://1.1.1.1/' 2>/dev/null | grep "Date:" |sed 's/Date: [A-Z][a-z][a-z], //g'| sed 's/r//') ; echo "Date Retrieved = $datetext" ; echo -n "Date set = " ; date -s "$datetext" -D'%d %b %Y %T %Z'
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Thanks to Twiglets
Here is an alternative that DOES set the date !!! [-s option].
Prints out 'Date' it retrieves & the 'Date' that is set for comparison.
This works on the AsusWRT / Merlin, the only thing that is odd is that the date retrieved is ".... GMT" and the date utility sets the correct time but changes it to "... DST"
Environment has TZ set to "GMT"
datetext=$(curl -I 'https://1.1.1.1/' 2>/dev/null | grep "Date:" |sed 's/Date: [A-Z][a-z][a-z], //g'| sed 's/r//') ; echo "Date Retrieved = $datetext" ; echo -n "Date set = " ; date -s "$datetext" -D'%d %b %Y %T %Z'
add a comment |Â
up vote
0
down vote
Thanks to Twiglets
Here is an alternative that DOES set the date !!! [-s option].
Prints out 'Date' it retrieves & the 'Date' that is set for comparison.
This works on the AsusWRT / Merlin, the only thing that is odd is that the date retrieved is ".... GMT" and the date utility sets the correct time but changes it to "... DST"
Environment has TZ set to "GMT"
datetext=$(curl -I 'https://1.1.1.1/' 2>/dev/null | grep "Date:" |sed 's/Date: [A-Z][a-z][a-z], //g'| sed 's/r//') ; echo "Date Retrieved = $datetext" ; echo -n "Date set = " ; date -s "$datetext" -D'%d %b %Y %T %Z'
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Thanks to Twiglets
Here is an alternative that DOES set the date !!! [-s option].
Prints out 'Date' it retrieves & the 'Date' that is set for comparison.
This works on the AsusWRT / Merlin, the only thing that is odd is that the date retrieved is ".... GMT" and the date utility sets the correct time but changes it to "... DST"
Environment has TZ set to "GMT"
datetext=$(curl -I 'https://1.1.1.1/' 2>/dev/null | grep "Date:" |sed 's/Date: [A-Z][a-z][a-z], //g'| sed 's/r//') ; echo "Date Retrieved = $datetext" ; echo -n "Date set = " ; date -s "$datetext" -D'%d %b %Y %T %Z'
Thanks to Twiglets
Here is an alternative that DOES set the date !!! [-s option].
Prints out 'Date' it retrieves & the 'Date' that is set for comparison.
This works on the AsusWRT / Merlin, the only thing that is odd is that the date retrieved is ".... GMT" and the date utility sets the correct time but changes it to "... DST"
Environment has TZ set to "GMT"
datetext=$(curl -I 'https://1.1.1.1/' 2>/dev/null | grep "Date:" |sed 's/Date: [A-Z][a-z][a-z], //g'| sed 's/r//') ; echo "Date Retrieved = $datetext" ; echo -n "Date set = " ; date -s "$datetext" -D'%d %b %Y %T %Z'
answered May 14 at 21:16
Tyler
264
264
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1035525%2fset-date-and-time-from-http-header-in-router-with-curl-or-wget%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
The last error message seems to be mangled, could you please edit and correct it?
â dessert
May 13 at 6:32
1
Possible duplicate of What is the command to update time and date from internet - Please review the second answer that is identical as your approach.
â pa4080
May 13 at 7:00
@dessert, updated! @Heyzeus/tmp/home/root# date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z " results in: date: invalid date '13 May 2018 22:46:44Z'. date -s requires something more like 2018-05-12 2018 18:49:18
â Tyler
May 13 at 22:47
or rather: date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)" results in: date: invalid date '13 May 2018 22:46:44'
â Tyler
May 13 at 22:53