If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > newbie aix shell script subtraction problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-06-04, 13:33
chinatrain99 chinatrain99 is offline
Registered User
 
Join Date: Sep 2003
Posts: 73
newbie aix shell script subtraction problem

This is driving me nuts. I am trying to write an AIX script to list files created last month. When I get the command working, i'm going to change the "ls -l" to a "rm" command. The code that subtracts 1 from pdate is giving me an error. How do I either subtract 1 from a field? Or how do I ask for the date in a ccyymm-1 format? What I want the script to give me is 200404 in the pdate field, not 200405. Thanks, any help would be greatly appreciated.

echo
. /home/db2inst1/.profile
pdate= date '+%Y%m'

pdate= $pdate - 1
$pdate >> cmsdevprune.rpt
ls -l /cmsbackt/COMMCMSD.0.cmsdev.NODE0000.CATN0000.${pdate}*.* >> cmsdevprune.rpt
Reply With Quote
  #2 (permalink)  
Old 05-07-04, 08:10
TimoV TimoV is offline
Registered User
 
Join Date: Dec 2003
Posts: 56
Somthing along the lines of:

Code:
pdate=`date +%Y%m` 

pdate=`expr $pdate - 1`
Might help you along the path to a solution...`
Reply With Quote
  #3 (permalink)  
Old 05-07-04, 09:41
chinatrain99 chinatrain99 is offline
Registered User
 
Join Date: Sep 2003
Posts: 73
this command doesn't work. i think the pdate field defaults to alpha and it won't subtract 1 from an alpha field. how do I make pdate a numeric field?
Reply With Quote
  #4 (permalink)  
Old 05-10-04, 07:48
TimoV TimoV is offline
Registered User
 
Join Date: Dec 2003
Posts: 56
I just tried thesde two commands again on m,y AIX 5.2 box in a ksh shell and they do exactly what you want...

Do an "echo $pdate" after both commands to see what the value of pdate is after each step...maybe that will show what is going wrong in your case...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On