- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to subtract time from $date within a script
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
Discussions
Discussions
Forums
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
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
тАО07-01-2010 06:00 AM
тАО07-01-2010 06:00 AM
how to subtract time from $date within a script
I have log file like the following but of course this will only look for today's date.
myFile="/fnsw/local/logs/elogs/elog"$(date +%Y%m%d);
Can i amend this in some way to look for logs with yesterday's date. I have seen -a option on man date but is that only when setting the date?
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 06:11 AM
тАО07-01-2010 06:11 AM
Re: how to subtract time from $date within a script
Use Perl;
# perl -MPOSIX -le 'print strftime "%m/%d/%Y",localtime(time-86400)'
...or capture the value like:
# DATE=$(perl -MPOSIX -le 'print strftime "%m/%d/%Y",localtime(time-86400)')
Of course, 86400 seconds is one-day (24*60*60).
You can create any date format you want using the same formatting directives you would use with 'date(1)'.
Regards!
...JRF...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 06:15 AM
тАО07-01-2010 06:15 AM
Re: how to subtract time from $date within a script
sorry I should have said it is korn shell script. Can I use localtime with that?
My script is like this
myFile="/fnsw/local/logs/elogs/elog"$(date +%Y%m%d);
serious=$(find $myFile -exec grep -l 'OPERATOR INTERVENTION' {} \;);
if [ -n "$serious" ]; then
mailx -s "Disk Message in FileNet elog" $MLIST < $myFile;
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 06:20 AM
тАО07-01-2010 06:20 AM
Re: how to subtract time from $date within a script
> sorry I should have said it is korn shell script. Can I use localtime with that?
You can use Perl to create a variable that represents yesterday's date. Your shell script simply invokes this tiny Perl snippet.
...
DATE=$(perl -MPOSIX -le 'print strftime "%m/%d/%Y",localtime(time-86400)')
myFile="/fnsw/local/logs/elogs/elog${DATE}"
...
The option you are thinking about is no doubt the GNU 'date' command. HP-UX lacks that functionality and we need to leverage Perl. This is no different than writing a shell script with snippets of 'sed' or 'awk'.
Regards!
...JRF...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 06:26 AM
тАО07-01-2010 06:26 AM
Re: how to subtract time from $date within a script
Oh, you want a year-month-day format, so re-arrange (as I said you could) the formatting directives. You want:
...
DATE=$(perl -MPOSIX -le 'print strftime "%Y/%m/%d",localtime(time-86400)')
myFile="/fnsw/local/logs/elogs/elog${DATE}"
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 06:31 AM
тАО07-01-2010 06:31 AM
Re: how to subtract time from $date within a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-01-2010 06:37 AM
тАО07-01-2010 06:37 AM
Re: how to subtract time from $date within a script
> I have no perl installed
I find that very hard to believe. What is your operating system -- post up 'uname -a'.
Perhaps the perl binary isn't in your PATH. Look for 'perl':
# find /usr /opt -name perl
If this is HP-UX you should find:
/opt/perl_32/bin/perl
/opt/perl_64/bin/perl
Create a symlink from '/usr/bin/perl' to either of the above.
Regards!
...JRF...