wanted to pass previous month number argument to the script
AIXThis forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would suggest doing the conversion to last month inside the test.sh script. Keep in mind you must decrement the year if the current month is January.
# For example, with command line: sh test.sh -f fuelevts_fdm `date '+%m'` `date '+%Y'`
# read in command line args into vars $MONTH and $YEAR:
[ "$3" ] && MONTH="$3"
[ "$4" ] && YEAR="$4"
# You could then set initial values for MONTH and YEAR, if none were given on command line:
[ "$MONTH" ] || MONTH=`date '+%m'`
[ "$YEAR" ] || YEAR=`date '+%Y'`
# Now calc last month and year, if required.
if [ "$MONTH" = "01" ]; then # January is the only special case.
MONTH=12
(( YEAR = $YEAR - 1 ))
# I am not sure the (( .. )) works in AIX, but if it doesn't, this will:
# YEAR=`expr $YEAR - 1`
else
(( MONTH = $MONTH - 1 ))
# MONTH=`expr $MONTH - 1`
[ "$MONTH" -lt 10 ] && MONTH="0$MONTH" # Pad the month with a zero, for consistency with date command.
fi
echo "Month=$MONTH, Year=$YEAR"
Last edited by anotherlinuxuser; 04-02-2014 at 01:21 AM.
When installing GNU coreutils, be careful not to overwrite the original programs. For example, install GNU-date as /usr/local/bin/date, and also make a symlink to it: ln -sf date /usr/local/bin/gdate, then call it:
If you don't want to install GNU date you can cheat and not do any date math by just taking the numerical month from 'date' and subtracting 1. Then you just test for and change 0->12 so it will properly wrap on January.
This works in ksh93; I didn't test it on my work boxes but it should work fine on the stock korn shell AIX ships with.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.