AIX - Get next month from current date


 
Thread Tools Search this Thread
Operating Systems AIX AIX - Get next month from current date
# 1  
Old 12-20-2013
AIX - Get next month from current date

As said in object, how can i obtain that?

In linux i use
HTML Code:
date -d "1 month" +"%m%Y"
.

Thanks i advance.
# 2  
Old 12-20-2013
With a recent version of the Korn shell, the built-in printf utility can process date reformatting requests such as:
Code:
printf '%(%m%Y)T\n' $(($(date +%m)+1))/01/$(date +%Y)

which, when run in December 2013, produces the output:
Code:
012014

I don't know whether the ksh on your AIX system is recent enough to support this, but it is worth a try.
# 3  
Old 12-20-2013
This is what i get with the command:

Code:
$ printf '%(%m%Y)T\n' $(($(date +%m)+1))/01/$(date +%Y)
(%Y)T
$

This is the AIX verison:

Code:
$ uname -a
AIX eb088sd7 3 5 00CDFD764C00
$


As workaround, i made this script:

Code:
typeset -Z2 nextMonth # to obtain 2 integer variable for month
 (01, 02, 03...)
#
# *******************************************************
#
nextMonth=`expr $(date +"%m") + 1`
# for adding 1 to Dec 12, i'll get 13, so restart from 1 setting nextMonth to 1
if [ $nextMonth -eq "13" ]; then
    let nextMonth='01'
    nextYear=`expr $(date +"%Y") + 1`
fi
#
nextMonthFlow=$nextMonth$nextYear


All that to "find" all filenames in a directory containing this date.
Example:

I have a file "56311_0161_012014_M1_25112013.csv" and the bold text is what i'm searching for.
That's why i'm incrementing my current month by 1, coz i launch in december the script for files of the next month.

The find command i use is:

Code:
for file in $(find $dir_01_in -name "*_$nextMonthFlow_*.[Cc][Ss][Vv]" -type f -print -prune); do

But it's not working as well, 'cause is giving all files in the directory to me, and not ONLY thoose corresponding to my find!

I'll appreciate all help.

Look further for yours.

Last edited by Don Cragun; 12-20-2013 at 09:34 PM.. Reason: Change QUOTE tags to CODE tags.
# 4  
Old 12-20-2013
Quote:
Originally Posted by fabfisc
This is what i get with the command:

Code:
$ printf '%(%m%Y)T\n' $(($(date +%m)+1))/01/$(date +%Y)
(%Y)T
$

This is the AIX verison:

Code:
$ uname -a
AIX eb088sd7 3 5 00CDFD764C00
$


As workaround, i made this script:

Code:
typeset -Z2 nextMonth # to obtain 2 integer variable for month
 (01, 02, 03...)
#
# *******************************************************
#
nextMonth=`expr $(date +"%m") + 1`
# for adding 1 to Dec 12, i'll get 13, so restart from 1 setting nextMonth to 1
if [ $nextMonth -eq "13" ]; then
    let nextMonth='01'
    nextYear=`expr $(date +"%Y") + 1`
fi
#
nextMonthFlow=$nextMonth$nextYear


All that to "find" all filenames in a directory containing this date.
Example:

I have a file "56311_0161_012014_M1_25112013.csv" and the bold text is what i'm searching for.
That's why i'm incrementing my current month by 1, coz i launch in december the script for files of the next month.

The find command i use is:

Code:
for file in $(find $dir_01_in -name "*_$nextMonthFlow_*.[Cc][Ss][Vv]" -type f -print -prune); do

But it's not working as well, 'cause is giving all files in the directory to me, and not ONLY thoose corresponding to my find!

I'll appreciate all help.

Look further for yours.
$nextMonthFlow_ is being expanded to an empty string. To keep from including the trailing underscore in the variable name, try the following command instead:
Code:
for file in $(find $dir_01_in -name "*_${nextMonthFlow}_*.[Cc][Ss][Vv]" -type f -print -prune); do

# 5  
Old 12-21-2013
Great!
Thanks.

About tar all file extracted, in my script, i have 2 alternatives:

1)
Quote:
tar -cvf test_ok.tar `find $(pwd)/03_ok/ -name "*.[Cc][Ss][Vv]" -type f -print -prune`
it works but returns the "test_ok.tar" including the entire path before, instead i want only files included in "/03_ok/", not the subdirectories

2)
Quote:
find $(pwd)/03_ok/ -name "*.[Cc][Ss][Vv]" -type f -print -prune -exec tar -cvf $(pwd)/05_backup/backup_ok.tar
returning an error

Quote:
$ find $(pwd)/03_ok/ -name "*.[Cc][Ss][Vv]" -type f -print -prune -exec tar -cvf $(pwd)/05_backup/backup_ok.tar
find: 0652-018 An expression term lacks a required parameter.
$
I also testet this code:

Code:
tar -cvf $dir_05_bck/03_ok_$adesso.tar `cd $dir_03_ok && find $dir_03_ok -name "*.[Cc][Ss][Vv]" -type f -print -prune && cd ..`

but with no luck, because the complete path is still there!

Last edited by fabfisc; 12-21-2013 at 12:23 PM..
# 6  
Old 12-21-2013
Quote:
Originally Posted by fabfisc
Great!
Thanks.

About tar all file extracted, in my script, i have 2 alternatives:

1)

it works but returns the "test_ok.tar" including the entire path before, instead i want only files included in "/03_ok/", not the subdirectories

2)

returning an error



I also testet this code:

Code:
tar -cvf $dir_05_bck/03_ok_$adesso.tar `cd $dir_03_ok && find $dir_03_ok -name "*.[Cc][Ss][Vv]" -type f -print -prune && cd ..`

but with no luck, because the complete path is still there!
Your requirements aren't clear. You have made some ambiguous statements about what isn't working with the code you've shown us, but you never really stated what set of files you are trying to archive. You haven't said much about your directory structure and you haven't told us what $dir_03_ok expands to. I'm guessing that you just want to archive the *.csv (case insensitive) files in the directory named by $dir_03_ok but want the pathnames in the archive to just be the filenames of the files rather than the absolute pathnames of those files. So, this is a wild guess, but try:
Code:
( cd "$dir_03_ok" && tar -cvf "$dir_05_bck/03_ok_$adesso.tar" `printf "%s\n" *.[Cc][Ss][Vv]` )

or, preferably (if you're using a POSIX compatible shell (like a 1993 or later version of ksh) rather than an old Bourne shell):
Code:
( cd "$dir_03_ok" && tar -cvf "$dir_05_bck/03_ok_$adesso.tar" $(printf "%s\n" *.[Cc][Ss][Vv]) )

# 7  
Old 12-22-2013
Quote:
Your requirements aren't clear.
I'm sorry Don, you are right.

Well, shortly, i'm trying to do what follow:

Code:
if "03_ok" and "04_ko" != empty then
      tar all ".csv" files of both dir to ./05_backup/backup_ok_ko_currentDate(ddmmYYYY_hhmmss).tar
elseif "03_ok" or "04_ko" != empty then
   if "03_ok" != empty then
      tar all ".csv" files
      tar all .cvs to ./05_backup/backup_ok_currentDate(ddmmYYYY_hhmmss).tar
   else
      tar all ".csv" files
      tar all .cvs to ./05_backup/backup_ko_currentDate(ddmmYYYY_hhmmss).tar
   end if
end if

clean dir "03_ok" and "04_ko" if != empty

read all ".cvs" files in a dir (not subdir), with, part of filename, containing adate in format "mmYYYY" (for the next month)
   for each file, call a (still unknow) script to copy it to another position
      if result of copy it's ok
         copy it to "03_ok" dir
      else
         copy it to "o4_ko" dir
      end if
   loop
loop


Last edited by fabfisc; 12-22-2013 at 12:09 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to get first & last day of a month from current date?

Hi, I need the first & last day of a month from any given date. For better understanding, if i need to back-fill data for date 07/20/2019 i.e July 20 2019, i need the first & last day has 07/01/2019 - 07/31/2019. FYI: I'm using GIT BASH terminal. sample code: export DT=$(date --date='6 days... (2 Replies)
Discussion started by: Rocky975583
2 Replies

2. Homework & Coursework Questions

How to minus 2 month from current date?

I am running a script in ksh to get the 2 months back date from system date.The below code is giving correct date output from putty command prompt.But while running the script is .ksh file it is giving the error below.Please suggest. ; d=a; y=a m-=num while(m < 1) {m+=12; y--}... (1 Reply)
Discussion started by: hini
1 Replies

3. Shell Programming and Scripting

Number of days in current month

I have a homework assignment: ---------------------------------------- "Display" the number of days in the current month. For example: September 1996 has 30 days ---------------------------------------- I am trying to just display the head of cal to start the sentence. eg. cal | head ... (1 Reply)
Discussion started by: eaafuddy
1 Replies

4. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

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

5. AIX

Get Next month in AIX from curent date in unix AIX

How could we derive teh Next month in MON-RR format from current date ie sysdate in UNI AIX sheel script.I coould get a command but i supports only inLinux susse andnotin AIX. I need for Unix AIX.Pls Help. Regards Shiv (2 Replies)
Discussion started by: SHIV75
2 Replies

6. Shell Programming and Scripting

current date - one month in AIX

Hi, i unable to get the last month date in AIX. current date - one month Based on the forums tried but did not find the relevent information. Any help grealy appriciated. Thanks Suri. (3 Replies)
Discussion started by: onesuri
3 Replies

7. Shell Programming and Scripting

How to extract log data based on current date and month ?

Hi Gurus, I'm using HP-UX B.11.23 operating system. I've been trying to extract this log info based on the current date and month, but was having some issues as the date column which on the 4th column has a comma and the 5th column has a dot tied to it. Here is the output from my shut... (5 Replies)
Discussion started by: superHonda123
5 Replies

8. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

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

9. Shell Programming and Scripting

How to find the create time of a file if current date is in next month

Hi All, I want to find the time diffrence between currnt time and "abc.txt" file create time. I have solve that but if the abc.txt file created last month then is there any process to find the difftent? Exp: Create time of abc.txt is "Apr 14 06:48" and currect date is "May 17 23:47".... (1 Reply)
Discussion started by: priyankak
1 Replies

10. Shell Programming and Scripting

delete files one day old in current month only

i want to delete files that are one day old condition is files should be of current month only ie if iam running script on 1 march it should not delete files of 28 feb(29 if leap year :-)} any modifications to find $DIR -type f -atime +1 -exec rm -f{}\; (4 Replies)
Discussion started by: maverick
4 Replies
Login or Register to Ask a Question