AIX - Get next month from current date

As said in object, how can i obtain that?

In linux i use

date -d "1 month" +"%m%Y"

.

Thanks i advance.

With a recent version of the Korn shell, the built-in printf utility can process date reformatting requests such as:

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

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

012014

I don't know whether the ksh on your AIX system is recent enough to support this, but it is worth a try.

This is what i get with the command:

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

This is the AIX verison:

$ uname -a
AIX eb088sd7 3 5 00CDFD764C00
$

As workaround, i made this script:

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:

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:

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

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:

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:

( 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):

( cd "$dir_03_ok" && tar -cvf "$dir_05_bck/03_ok_$adesso.tar" $(printf "%s\n" *.[Cc][Ss][Vv]) )

I'm sorry Don, you are right.

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

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

The version 5.3 which thread-owner showed is already out of support, but the following is true for the latest versions (7.1) either:

AIX uses a ksh88 as the default system shell ( /bin/ksh ), but comes with a ksh93 per default. One will have to use /bin/ksh93 to access it, though.

I hope this helps.

bakunin

PS: sitting at my office keyboard now i am able to expand on that:

The basic system default shell is a ksh88 and its version string is: Version M-11/16/88f . This has not changed in ages and is true for probably all the AIX systems you will ever encounter, because i doubt you will have a chance to see a pre-3.2.5-system running somewhere.

The /bin/ksh93 produces the version string Version M 93t+ 2009-05-01 issued from a 7.1-system patched to the latest level. I cannot check on any 5.3-system (they are out of support and we do not have any), but IIRC the later releases of 5.3 used the same ksh93 version. 6.1 definitely does.

I hope this helps.

bakunin

This is still confusing. "03_ok" and "04_ko" appear to be strings (and are clearly not empty strings). Are they the names of subdirectories in the current directory? Are they the names of variables that expand to absolute pathnames of directories? Are they the names of variables that expand to relative pathnames of directories?

What do you mean by != empty ? Do you mean that the directory to which they refer does not contain any files other than . and .. , does not contain any files with names ending in .csv , or something else (and, if so, what)?

What is another position to which files are to be copied?
You have references to *.csv and *.cvs . Are the references to *.cvs supposed to be *.csv , or do you really have files with both suffixes?

It sounds like you have a directory that contains some .csv (or .cvs or both) and you want to copy those files from one directory into a tar archive, then you want to try to copy those same files to another directory and then copy the same file to a third or fourth directory depending on whether the 2nd copy succeeded or failed. Do you really need four copies of each of these files (or were one or more of the copy it to statements intended to be move it to )?