- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Date option in scripting
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
тАО09-03-2007 02:21 AM
тАО09-03-2007 02:21 AM
Sep 2
This is so that I can write a script to grep the date with below command
yesterday=`TZ=GMT+23 date | cut -d " " -f 2,3,4`
cat /var/adm/syslog/syslog.log | grep "$yesterday" | grep -i -E 'crit|warn|ftp'
The problem is that on Monday I need to get the list from Fridays date ( syslog is just an example and I will be using the script to get other date related logs as well)
How can I achieve this?
I tried caljd.sh and can achieve this but the format is as below, Is there a way that I can change the format
Caljd.sh date:
YESTERDAY=$(caljd.sh -y -s $(caljd.sh -p 3))
echo "Yesterday = ${YESTERDAY}"
яГШ Yesterday = 20070831
The sample script is below, might help you to understand what I want to achieve
#!/usr/bin/sh
yesterday=`TZ=GMT+23 date | cut -d " " -f 2,3,4`
# Caljd command can also be used for friday
#friday=`TZ=GMT+?? date | cut -d " " -f 2,3,4`
HOSTNAME=`uname -n`
weekday=`date -u +%w`
if ((weekday =1))
then
echo "This is $HOSTNAME server"
# syslog
echo "Syslog for $HOSTNAME"
echo
cat /var/adm/syslog/syslog.log | grep "$friday" | grep -i -E 'warn|crit'
else
# syslog
echo "Syslog for $HOSTNAME"
echo
cat /var/adm/syslog/syslog.log | grep "$yesterday" | grep -i -E 'ftp'
fi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2007 02:29 AM
тАО09-03-2007 02:29 AM
Re: Date option in scripting
Few places to look for date help.
http://hpux.ws/merijn/caljd-2.25.sh
http://hpux.ws/merijn/caljd-2.2.pl
LOGFILE="/tmp/memuse.mon.${FILTER}-`date +%d-%b-%Y`.log"
The above two utilities, written by A. Clay Stephenson do a lot of troublesome date stuff for you.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2007 02:48 AM
тАО09-03-2007 02:48 AM
Re: Date option in scripting
use perl;
# perl -MPOSIX -e 'print strftime "%b %1d\n",localtime(time-86400)'
'strftime' returns fileds just like you return formatted fields from 'date'. The computations occur in Epoch seconds; hence the current localtime less 86.400 seconds is exactly yesterday.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2007 03:28 AM
тАО09-03-2007 03:28 AM
Re: Date option in scripting
What was it about the Perl script that didn't satisfy your original objective?:
> want to get yesterdays date in below format
Sep 2
# yesterday=$(perl -MPOSIX -e 'print strftime "%b %1d\n",localtime(time-86400)')
ALSO:
You can drop the useless 'cat' and let 'grep' open and read the file:
# grep "${yesterday}" /var/adm/syslog/syslog.log | grep -i -E 'crit|warn|ftp'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2007 04:43 AM
тАО09-03-2007 04:43 AM
Solutioncaljd.sh -o $(caljd.sh -x 6 -x 0 -p 1) | read MO DAY YEAR
echo "${MO} ${DAY}"
The -x 6 says skip past Saturdays; -x 0 skips past Sunday, -p 1 says 1 previous day.
-o says print abbreviated month names rather than numeric months.
We read the year but ignore it in the echo. All of this was in the usage of caljd.sh. Invoke as caljd.sh -u for full usage and many examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2007 05:50 AM
тАО09-03-2007 05:50 AM
Re: Date option in scripting
My apologies for not reading! You *did* say:
> The problem is that on Monday I need to get the list from Fridays date
Clay's script is an answer that works without re-invention AND has a plethora of useful options. To redeem my failure to read, you could use this Perl script:
# cat .prevworkday
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
my $t = time();
my $d = strftime( "%u", localtime($t) );
my $n = $d == 1 ? 3 : $d == 7 ? 2 : 1;
print strftime "%b %1d\n", localtime( $t - ( $n * 86400 ) );
1;
...run as:
./prevworkday
Aug 31
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2007 02:30 AM
тАО09-04-2007 02:30 AM
Re: Date option in scripting
With your help I will be able to complete my script