03-19-2008
How to get the Previous month in Korn Shell
Try this.
#!/bin/ksh
curmth=`date +%m`
set -A mth Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
prevmth=${mth[$((curmth - 1))]}
echo $prevmth
# end of file #
-Ramesh
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
This has probably been asked 100 times, but I couldn't find any articles on point. I have a script that runs on the last day of every month at 11:30pm. If cats a number of input tables that were created the previous month (or earlier), combines them into one master file and erases the indivual... (1 Reply)
Discussion started by: beilstwh
1 Replies
2. Shell Programming and Scripting
Hi,
My task to to delete files which are of previous months.
I have files named as follows *CCYYMMDD.xls. on a particular day i have delete previous months files
i.e in Dec i have delete all nov files which look like 200511DD.XLS
in Jan i have to delete all Dec files 200512DD.xls
... (7 Replies)
Discussion started by: savitha
7 Replies
3. Shell Programming and Scripting
Hi, I'm new with Unix, I'm trying to get a last day of previous month with this format: %b %d %Y (example: Feb 25 2008).
Here is what I have so far.
#!/bin/ksh
cur_month=`date +%m`
cur_year=`date +%Y`
prev_month=$(($cur_month-1))
# Check to see if this is January
if
then
... (11 Replies)
Discussion started by: sirrtuan
11 Replies
4. UNIX for Dummies Questions & Answers
Hello,
I'm new to shell scripting.
We've develop a script which will grep a file on the search criteria, MON (Jan/Feb/Mar/etc). But we should set this sript in cron which will run on every first day of the month. The problem I'm having is, when I run the script, it is displaying the contents of... (7 Replies)
Discussion started by: suneelj
7 Replies
5. Shell Programming and Scripting
Can someone help me creating a function which will give me previous months.
like for example if the date is 200902 and if i call my function and pass a parameter 2 i want to get 200812 as the answer.
or if i pass 200902 with a parameter 7 then my function should give me the date as 200807. (1 Reply)
Discussion started by: Lincy
1 Replies
6. UNIX for Dummies Questions & Answers
Hi folks
month=`date +%m`gives current month
Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies
7. UNIX for Dummies Questions & Answers
Hi All,
I am using the below code to get the year and month from date:
Below gives output like 201212.
dt=`date '+%Y%m'`
how do i get the previous month value(ie: subtract 1 from date)
example output:
dt=201211
Please help. :confused: (3 Replies)
Discussion started by: abhi_123
3 Replies
8. Shell Programming and Scripting
I have requirment to get last date of previous month and the first date of previous 4th month:
Example:
Current date: 20130320 (yyyymmdd)
Last date of previous month: 20130228 (yyyymmdd)
First date of previous 4th month: 20121101 (yyyymmdd)
In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies
9. Shell Programming and Scripting
could you please assist the below query.
i had written the below piece of code to copy the files from one directory to another. For current month files had been copied ,unfortunately the previous month files not copied.
Please find the below directory structure:-
ls -lrt
total 1824... (2 Replies)
Discussion started by: venkat918
2 Replies
LEARN ABOUT CENTOS
function::ctime
FUNCTION::CTIME(3stap) Time utility functions FUNCTION::CTIME(3stap)
NAME
function::ctime - Convert seconds since epoch into human readable date/time string
SYNOPSIS
ctime:string(epochsecs:long)
ARGUMENTS
epochsecs
Number of seconds since epoch (as returned by gettimeofday_s)
DESCRIPTION
Takes an argument of seconds since the epoch as returned by gettimeofday_s. Returns a string of the form
"Wed Jun 30 21:49:08 1993"
The string will always be exactly 24 characters. If the time would be unreasonable far in the past (before what can be represented with a
32 bit offset in seconds from the epoch) an error will occur (which can be avoided with try/catch). If the time would be unreasonable far
in the future, an error will also occur.
Note that the epoch (zero) corresponds to
"Thu Jan 1 00:00:00 1970"
The earliest full date given by ctime, corresponding to epochsecs -2147483648 is "Fri Dec 13 20:45:52 1901". The latest full date given by
ctime, corresponding to epochsecs 2147483647 is "Tue Jan 19 03:14:07 2038".
The abbreviations for the days of the week are 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', and 'Sat'. The abbreviations for the months are
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', and 'Dec'.
Note that the real C library ctime function puts a newline ('
') character at the end of the string that this function does not. Also note
that since the kernel has no concept of timezones, the returned time is always in GMT.
SystemTap Tapset Reference June 2014 FUNCTION::CTIME(3stap)