- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- getting epoch time through shell
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2003 07:46 AM
10-31-2003 07:46 AM
I know how to do this easy enough with perl, but what I need this for perl will not work, it has to be a shell script..
basically it would need to convert something like:
Fri Oct 31 15:44:42 EST 2003
into:
1067633082
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2003 07:58 AM
10-31-2003 07:58 AM
Re: getting epoch time through shell
http://forums1.itrc.hp.com/service/forums/questionanswer.do?admit=716493758+1067633578166+28353475&threadId=7848
-Rusty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2003 08:03 AM
10-31-2003 08:03 AM
Re: getting epoch time through shell
Here is a little background on my situation...basically we have this third party software that "web enables" some of our applications...well, and I am not sure of all the details, but basically it has the ability to run home-grown scripts, but it reads in the script and converts it into some format that it understands...which, obviously causes it to bawk when it see's a perl script....I even tried getting around it by just having a shell script call the perl script and it still bawks...I have a feeling it will freak out when it see's a C prog also...
dont ask me, I didnt write this stupid thing :P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2003 08:18 AM
10-31-2003 08:18 AM
Re: getting epoch time through shell
Perl is definitely the way to do this.
If you must, I can probably get you very close with caljd.sh -- although the timezone stuff makes this problem more difficult. If the datestamps can be done UT rather than local timezones then this is a much simpler exercise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2003 08:25 AM
10-31-2003 08:25 AM
Re: getting epoch time through shell
Does other unix commands work, i.e. grep, sed, awk, etc. after all they are compiled C programs, just like the shell is.
Maybe your application will only execute commands found in a specific location, i.e. has it's own PATH variable (or equiv) setup.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2003 08:47 AM
10-31-2003 08:47 AM
Re: getting epoch time through shell
all I know about this product is this:
the users, from the web, run a script called menu.sh...
in this script it has echo's, read's, if checks and case statements..other than that, no commands except shell programs in the case statements...like if the user picks option 1, it runs this script..
but you are right...in the shell scripts that it calls, they use stuff like grep and awk...which is compiled....so perhaps a C program will work, I will try it on Monday...
as for perl, when I try to run a perl script (which works manually from command line) it actually just hangs forever and starts churning on the CPU until it is manually killed. so I am unclear as to what the problem is with that...
I was kind of just hoping that there was already a script written out there somewhere that did this...Oh, and the timezone doesnt make a difference really...basically I need the epoch time for comparisons, like was Jul 22nd, 15:44 2003 90 days ago? if so, then do this...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2003 09:20 AM
10-31-2003 09:20 AM
SolutionI'll do this in POSIX/ksh but you might have to use expr if this is a really dumb shell.
DT="Jul 22 2003"
DIFF=$(( $(caljd) - $(caljd.sh -i ${DT}) ))
if [[ ${DIFF} -ge 90 ]]
then
echo "This here is 90 days or older"
fi
Invoke as caljd.sh -u for full usage. You can also yank out the cal_jdate function and use it directly. It takes three numerical args: month, day, year and converts them to a JulianDay --- number of days since Jan 1, 4713 BCE. Differences are then easy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2003 11:15 PM
10-31-2003 11:15 PM
Re: getting epoch time through shell
maybe the attached script can help you. In order to achieve the requested, it has to be fed correctly, e.g.:
# ./return_seconds 1970 2003 10 31 15 44 42
which produces this result:
1067615082
The parameters are explained in the script: no. 1 is the year to count back to; the script counts back to midnight of $1. The other six parameters are the year, month etc, from which you count.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 07:38 AM
11-03-2003 07:38 AM
Re: getting epoch time through shell
yes, both of the above will work :)
One thing to mention though, on the return_seconds script, the way that is written, the timezone does make a differance, because midnight 1970 is not really 0 seconds epoch, it is 6 hours off when running in EST...I think I will play around with the script to hard code in the date of Dec 31 19:00:00 1969 as being the start time :)
Thanks for your assistance :)