1

I am trying to get the number of seconds since the epoch in both Solaris 10 and Solaris 11.

On Solaris 11, "date +%s" is giving me the output (from bash), but the same is failing on Solaris 10.

What is the right command in Solaris 10?

  • I have a C program for this which uses SIGUSR1 to output to the screen if you want... – Mr. Minty Fresh Mar 9 '16 at 15:28
  • Please review suggested answers and mark one as solution if it works for you. Otherwise add comments so we can further improve the answers. – Svetlin Tonchev Mar 10 '16 at 7:25
5

I would use nawk:

nawk "BEGIN{print srand}"
  • Gives a syntax error at my end? – EightBitTony Mar 9 '16 at 13:53
  • I just ran it on my solaris 10 cluster and it worked. Can you verify you don't miss typed it? – Svetlin Tonchev Mar 9 '16 at 13:54
  • I appreciate the OP's query is specifically about Solaris, so it's a valid answer, but that format doesn't work on Linux and if I use srand() I get 1 as the output. I believe it's using an undocumented feature, rather than a function for which it's designed and may not be reliable long-term. Are you sure you ran srand and not srand()? – EightBitTony Mar 9 '16 at 13:56
  • Thank you for your remark. I don't think it does matter are you using srand or srand(). Still i tested it both ways on my solaris 10 test server and it worked. – Svetlin Tonchev Mar 9 '16 at 15:59
  • 1
    @EightBitTony The use of srand to get time of day via nawk is documented in the Solaris nawk man page. – Andrew Henle Mar 9 '16 at 19:02
0

I usually revert to perl for this, assuming it is installed.

perl -e 'print time."\n";'

For example,

$ perl -e 'print time."\n";'
1457531088

Assuming perl is installed, it should be pretty much OS independent .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.