-
1. Re: Epoch time in NSH
Bill RobinsonApr 18, 2012 11:15 AM (in response to Alexandru Ghionghios)
Modload zsh/datetime
Use strftime.
You need to be using n/zsh 4.3.4
-
2. Re: Epoch time in NSH
Wenchi LiaoApr 18, 2012 1:37 PM (in response to Bill Robinson)
if the datetime module is there, EPOCHSECONDS will be the current time as well:
$ echo $EPOCHSECONDS
1334773831
$
If the newer zsh isn't available, awk can generate it as well:
$ echo $EPOCHSECONDS
1334774032
$ echo "" | awk 'END {print srand()}'
1334774034
$
-
3. Re: Epoch time in NSH
Bill RobinsonApr 18, 2012 1:39 PM (in response to Wenchi Liao)
Are you using the nsh awk or the system awk?
-
4. Re: Epoch time in NSH
Wenchi LiaoApr 18, 2012 5:39 PM (in response to Bill Robinson)
It shouldn't matter. awk should have the srand() function, and that's what makes this work. With no arguments, srand() will return the current time in seconds.
playing around with this a bit more. It seems gnu awk always (some versions?) implicitly seed to 1, so gawk may need srand twice:
$ echo "" | gawk 'END{print srand()}'
1
$ echo "" | gawk 'END{print srand()}'
1
$ echo "" | gawk 'END{srand(); print srand()}'
1334788707
echo "" | gawk 'END{srand(); print srand()}'
1334788708
nsh awk only needs one... eh..
-
5. Re: Epoch time in NSH
Alexandru Ghionghios Apr 19, 2012 10:31 AM (in response to Alexandru Ghionghios)Thanks for your answers.
I am using nsh's awk. I am able to do it this way, as you suggested:
echo "" | awk 'END {print srand()}'
Meantime, I found perl on the application server so I was able to do it using perl:
perl -e "print time"
I cannot update nsh to a newer version. This is the version I got: BladeLogic Network Shell 8.0.7.731. Don't have gawk ar nawk...
Thanks a lot for your help!!
Regards,
Alex
-
6. Re: Epoch time in NSH
Bill RobinsonApr 20, 2012 12:50 PM (in response to Alexandru Ghionghios)
1 of 1 people found this helpfulYou can update nsh – actually zsh.
To check the version run:
Nsh –version
That will show like:
$ nsh --version
zsh 4.3.4 (i686-pc-linux-gnu)
if it’s 4.0.4 you can goto the NSH/bin directory and change the nsh symlink to point to the zsh-4_3_4 binary instead of zsh. 4.3.4 is the default for bsa 8.1+ and it works fine in older versions for the most part.