need to manipulate dates
I'm trying to run a script in Bourne shell (solaris8) that executes on the first day of the month and passes the numeric representation of the previous month.
Getting the current month numeric is not a problem. MONTH=`date +%m`` I just can't seem to remember how to add/subtract variables.... :confused: |
echo $(( 5 + 3 ))
|
lost something in the translation....
# month=`date +%m` # echo $month 08 # echo $((month -1)) syntax error: `(' unexpected |
sorry, my fault, just checked the sh on solaris and it doesnt work, strange though, it works on my sh. anyway, the old way is to use expr.
$ month=`date +%m` $ echo $month 08 $ echo `expr $month - 1` 7 |
THANKS...Works like a champ.
If you are interested....here's the code #!/bin/sh # # Script to run Wusage 7.0 stats # This script assumes that the conf files are in # the same directory as the wusage executable # Usage: run_stats.sh conf_File_name # Define values WUSAGE_DIR="/data/projects/doedir/serversII/wusage7.0" CONF_FILE="$WUSAGE_DIR/1" CURRENT_MONTH=`date +%m` CURRENT_YEAR=`date +%y` MONTH=`expr $CURRENT_MONTH - 1` BEGIN_DATE=`echo "$MONTH/1/$CURRENT_YEAR"` END_DAY=`cal $MONTH $CURRENT_YEAR | awk '/./{day=$NF};END {print day}'` END_DATE=`echo "$MONTH/$END_DAY/$CURRENT_YEAR"` # Run stats cd $WUSAGE_DIR ./wusage -c $CONF_FILE -b $BEGIN_DATE -e $END_DATE exit 0 |
Ooopps ...fond an error. Here's the revised code.
#!/bin/sh # # Script to run Wusage 7.0 stats # This script assumes that the conf files are in # the same directory as the wusage executable # Usage: run_stats.sh conf_File_name # Define values WUSAGE_DIR="/data/projects/doedir/serversII/wusage7.0" CONF_FILE="$WUSAGE_DIR/$1" CURRENT_MONTH=`date +%m` CURRENT_YEAR=`date +%y` MONTH=`expr $CURRENT_MONTH - 1` BEGIN_DATE=`echo "$MONTH/1/$CURRENT_YEAR"` END_DAY=`cal $MONTH $CURRENT_YEAR | awk '/./{day=$NF};END {print day}'` END_DATE=`echo "$MONTH/$END_DAY/$CURRENT_YEAR"` # Run stats cd $WUSAGE_DIR ./wusage -c $CONF_FILE -b $BEGIN_DATE -e $END_DATE exit 0 |
All times are GMT -5. The time now is 07:56 AM. |