Determining the last day of a month in a shell script can be complicated because each month has a different number of days, and because of leap year. Here's a trick with the "date" command that simplifies this calculation. I use it to archive rotating monthly logs, and run end of the month reports.
#!/usr/bin/ksh
# Pacific Time: TZ=-16 (see below for explanation)
if [ `TZ=-16 date +%d` = "01" ]; then
# Run these commands ...
fi
The timezone setting (TZ) setting tricks the date command into thinking it is 24 hours ahead. The syntax is counter intuitive. First, the "-" sign means forward, and a "+" sign means backward. Second, "TZ" is relative to GMT time. To illustrate, here are a few examples that set the timezone ahead one day:
GMT: TZ=-24
EST: TZ=-19
CST: TZ=-18
PST: TZ=-16
This trick can be used to calculate yesterday, tomorrow or two weeks from now.
This is blog for IT Infrastructure consultants , who want to use latest technologies for building high profile solutions with reliability and high performance.
Subscribe to:
Post Comments (Atom)
How to Enable Graphical Mode on Red Hat 7 he recommended way to enable graphical mode on RHEL V7 is to install first following packages # ...
-
Putting the physical control panel in manual operating mode There are many instances , where you want to use ASMI interface to login to Hype...
-
While Lpars and Wpars are both virtualization features of IBM Power systems , there are inherently differences which do reside between Lpars...
-
Have u met any auditor who ask you about security of your backups? For most of system and database administrators it is an annoying question...
No comments:
Post a Comment