tag:blogger.com,1999:blog-31367897.post115334113493184822..comments2023-10-02T04:08:23.844-05:00Comments on Solaris Jedi: Solaris Date command and epoch timecghubbellhttp://www.blogger.com/profile/03949787282885281381noreply@blogger.comBlogger29125tag:blogger.com,1999:blog-31367897.post-51908269823464777992014-08-20T15:27:04.648-05:002014-08-20T15:27:04.648-05:00Just to report that in Solaris 11 "date +%s&q...Just to report that in Solaris 11 "date +%s" does work now.Nestor Urquizahttps://www.blogger.com/profile/12351754666722274569noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-42560544036592020312014-04-10T02:56:13.778-05:002014-04-10T02:56:13.778-05:00Thats really a great post. Thanks for the post.Thats really a great post. Thanks for the post.Melanihttps://www.blogger.com/profile/12180225438910358245noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-9136844211117354602013-11-04T14:18:22.544-05:002013-11-04T14:18:22.544-05:00nawk 'BEGIN{print srand()}'
# nawk 'B...<br />nawk 'BEGIN{print srand()}'<br /><br /># nawk 'BEGIN{print srand()}'<br />1275407044 <br /><br />Works for both Solaris 10 and 11.<br /><br />but "truss date" only works for Solaris 10 or below.Artspherehttps://www.blogger.com/profile/03778168581558388831noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-46366974200998554282013-03-11T15:54:02.787-05:002013-03-11T15:54:02.787-05:00Almost 6 years after your post and still no +%s in...Almost 6 years after your post and still no +%s in Solaris 10 date. I keep coming back to this and I said I better leave at least a BIG THANK YOU!Nestor Urquizahttps://www.blogger.com/profile/12351754666722274569noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-83976245261138714242013-02-03T00:17:44.208-05:002013-02-03T00:17:44.208-05:00Thanks, man. Nice snippet; saved me from having t...Thanks, man. Nice snippet; saved me from having to write some C/Java code.trbothttps://www.blogger.com/profile/17265088202432959453noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-60626357923542594462012-12-14T01:49:44.654-05:002012-12-14T01:49:44.654-05:00Finding epoch time for current date and time is no...Finding epoch time for current date and time is not a big deal. But how do we get epoch seconds for a user given date like "Fri Dec 11 11:08:46 IST 2011"Anonymoushttps://www.blogger.com/profile/14831359227065624278noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-68110020522620323792012-12-14T01:46:35.674-05:002012-12-14T01:46:35.674-05:00To get the epoch time for current date and time is...To get the epoch time for current date and time is not a big deal but to get epoch time for a user given date like "Tue Nov 11 11:08:46 IST 2011"Anonymoushttps://www.blogger.com/profile/14831359227065624278noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-41310496144414363292011-10-10T00:56:41.320-05:002011-10-10T00:56:41.320-05:00This will allow you to calculate values in the fut...This will allow you to calculate values in the future or in the past. This takes the value from epoch time creates it as an integer for calculation.<br /><br />Epochtime=$(nawk 'BEGIN{print srand()}')<br /><br />echo $Epochtime<br /><br />echo "0t${Epochtime}=Y" | /usr/bin/adb<br /><br />Epoch=`expr $Epochtime + 43200`<br /><br />echo "after 12 hrs = $Epoch"<br /><br />echo "0t${Epoch}=Y" | /usr/bin/adbJThttps://www.blogger.com/profile/13535029536650464855noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-57805959659259506702011-09-04T04:16:57.206-05:002011-09-04T04:16:57.206-05:00Here's a pure POSIX solution without the need ...Here's a pure POSIX solution without the need for the truss hack.<br /><br />#!/bin/sh<br />: > x<br />echo "ibase=8;$(pax -wx cpio x | cut -c 48-59)" | bc<br />rm x<br /><br />Lets see what this prints:<br /><br />$ ./x.sh; date +%s<br />1314820066<br />1314820066attoparsechttps://www.blogger.com/profile/14309577283482448081noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-20719574585066618642011-07-20T02:37:52.387-05:002011-07-20T02:37:52.387-05:00Thanks, this is really helpfullThanks, this is really helpfullJagRuthttps://www.blogger.com/profile/02169287908458404726noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-80584303961453312542011-05-04T07:34:25.523-05:002011-05-04T07:34:25.523-05:00sed -n 3p mmm.ttt
will return the following:
...sed -n 3p mmm.ttt<br />will return the following:<br /> May 4 2011 3:00PM <br /><br />I need to convert it to seconds since epoch and then subtract it from the current date (again in seconds since epoch), to see the time difference.<br /><br />Another word: i've a file which contains a date like described above. I need to read this date and compare it with current date, to see if the difference is more than 3 hours or not.<br /><br />Could you please help me with a script?artsxhttps://www.blogger.com/profile/11471568856351482931noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-41894162645247437732010-06-25T10:06:08.843-05:002010-06-25T10:06:08.843-05:00Thanks. This really works. But how do I get epoch ...Thanks. This really works. But how do I get epoch seconds for a date other than now? e.g. I want to find epoch seconds till 19th June 2006.BulletRiphttps://www.blogger.com/profile/04272388206233383639noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-65224918966195064472010-06-01T10:56:08.368-05:002010-06-01T10:56:08.368-05:00found that:
nawk 'BEGIN{print srand()}'
...found that:<br /><br />nawk 'BEGIN{print srand()}'<br /><br /># nawk 'BEGIN{print srand()}'<br />1275407044Unknownhttps://www.blogger.com/profile/14261931513161180942noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-89287140464387913762010-05-10T13:51:32.648-05:002010-05-10T13:51:32.648-05:00Perl does actually eclipse the hack in terms of sh...Perl does actually eclipse the hack in terms of sheer speed, but the hack offered works pretty slick if I might say so myself: <br /><br />/tmp<br />-> time truss date 2>&1 |grep "^time" |sed "s/[ \t]/ /g" |cut -d' ' -f3<br />1273517121<br /><br />real 0m0.08s<br />user 0m0.01s<br />sys 0m0.06s<br /><br />/tmp<br />-> time truss date 2>&1 |grep ^time |awk '{print $3;}' <br />1273517125<br /><br />real 0m0.09s<br />user 0m0.01s<br />sys 0m0.05s<br /><br />/tmp<br />-> time perl -e 'print time; ' <br />1273517128<br />real 0m0.03s<br />user 0m0.00s<br />sys 0m0.01s<br /><br />I'd venture a guess that the cause for Solaris to ignore it is that it's low-hanging, but can be hacked such as this... <br /><br />Thanks!nVertedhttps://www.blogger.com/profile/12856388086812412223noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-70439393815146972062010-03-23T11:50:10.342-05:002010-03-23T11:50:10.342-05:00Thank you.Thank you.Unknownhttps://www.blogger.com/profile/14031982750462812822noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-14156107856968910432010-02-02T05:38:49.173-05:002010-02-02T05:38:49.173-05:00Thanks a lot
you're genious :)
perl does the s...Thanks a lot<br />you're genious :)<br />perl does the same with this command : perl -e 'print time, "\n"'<br /><br />But yours is more portable<br /><br />Thanks !Anonymoushttps://www.blogger.com/profile/05877691789828274206noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-46820589629636235552009-11-17T09:11:35.791-05:002009-11-17T09:11:35.791-05:00Hi,
Is it possible to subtract 600 seconds from th...Hi,<br />Is it possible to subtract 600 seconds from this value and then convert the same into date once again?<br />Regards<br />KarthickKarthickhttps://www.blogger.com/profile/12685233157188790098noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-50485220076069176102009-07-17T09:40:02.979-05:002009-07-17T09:40:02.979-05:00Thanks, that was helpful.
DanThanks, that was helpful. <br /><br />DanAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-31367897.post-70632116547436801692008-08-13T06:04:00.000-05:002008-08-13T06:04:00.000-05:00s.a.m.,That's a great question. Perl is actually ...s.a.m.,<BR/><BR/>That's a great question. Perl is actually very light weight, and I would imagine that its overhead could be even lighter than my hack. So in your described scenario I would put the odds in favor of Perl.<BR/><BR/>The biggest reason I don't go that direction for general use is that if I have a requirement that dictates shell for the primary routine, I find it tends to complicate maintainability to call perl from within shell. I prefer to pick the tool that best solves the overall problem.<BR/><BR/>That being said, most of the time Perl makes the best hammer, and I always prefer to write Perl over shell. Someday I hope some of the incompatibilities (like the packaging system) can be addressed.cghubbellhttps://www.blogger.com/profile/03949787282885281381noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-46011028044277823912008-08-12T08:50:00.000-05:002008-08-12T08:50:00.000-05:00It is absolutely embarrassing that solaris date() ...It is absolutely embarrassing that solaris date() doesn't have this. Good tip.Stevenhttps://www.blogger.com/profile/04068217923979593122noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-77816313240777141462008-06-19T08:54:00.000-05:002008-06-19T08:54:00.000-05:00Thanks! This was a big help in a crunch. It's comp...Thanks! This was a big help in a crunch. It's completely unclear to me why Solaris still ships with an ancient date(1) that doesn't support %s as on GNU Date.Mark Lindseyhttps://www.blogger.com/profile/08995576111457955321noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-68145906200059265412008-04-30T08:17:00.000-05:002008-04-30T08:17:00.000-05:00Thanks! Very smart and useful. About using perl in...Thanks! Very smart and useful. About using perl instead, if you are running a loop within a ksh script that requires the current epoch time on every loop, which command would be less taxing? a truss/date/grep/nawk or a perl interpreter invocation? <BR/>You would think that staying "within" the shell would be faster. Not sure! Will probably need to test/measure it to find out! What are your thoughyts?Anyway, I like the technique, Smart!S.A.Mhttps://www.blogger.com/profile/06552047104767201849noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-28022096672769737542008-04-16T05:47:00.000-05:002008-04-16T05:47:00.000-05:00I guy,i'm a problem. In linux have a:DATE_LDAPSEC=...I guy,<BR/>i'm a problem. In linux have a:<BR/>DATE_LDAPSEC=`date +%s -d "$LDAP_DATE"`<BR/>but the "-d" option is not replicable whit your script.<BR/>Any ideas for substitution???@b34tf00thttps://www.blogger.com/profile/13748773959241705781noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-19703651629482232792008-03-21T08:41:00.000-05:002008-03-21T08:41:00.000-05:00That's awesome, thanks! -bernardthered (3/21/08)That's awesome, thanks! <BR/><BR/>-bernardthered (3/21/08)bernardtheredhttps://www.blogger.com/profile/08270402166187706604noreply@blogger.comtag:blogger.com,1999:blog-31367897.post-30420293171186813332008-02-28T13:38:00.000-05:002008-02-28T13:38:00.000-05:00Thank you!I usually have various GNU utilities ins...Thank you!<BR/>I usually have various GNU utilities installed from Blastwave, but I was in a situation where I needed this fix.Berkhttps://www.blogger.com/profile/11130253259593086256noreply@blogger.com