LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-15-2003, 12:00 PM   #1
clsonnt
LQ Newbie
 
Registered: Jun 2003
Distribution: Redhat
Posts: 14

Rep: Reputation: 0
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....
 
Old 08-15-2003, 12:22 PM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
echo $(( 5 + 3 ))
 
Old 08-15-2003, 12:33 PM   #3
clsonnt
LQ Newbie
 
Registered: Jun 2003
Distribution: Redhat
Posts: 14

Original Poster
Rep: Reputation: 0
lost something in the translation....

# month=`date +%m`
# echo $month
08
# echo $((month -1))
syntax error: `(' unexpected
 
Old 08-15-2003, 01:16 PM   #4
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
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
 
Old 08-19-2003, 10:00 AM   #5
clsonnt
LQ Newbie
 
Registered: Jun 2003
Distribution: Redhat
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 08-19-2003, 10:07 AM   #6
clsonnt
LQ Newbie
 
Registered: Jun 2003
Distribution: Redhat
Posts: 14

Original Poster
Rep: Reputation: 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Linux manipulate Windows partition? joshknape Linux - Newbie 6 09-11-2005 07:37 AM
manipulate the floppy bruse Mandriva 1 02-22-2005 07:49 AM
bash + manipulate stdout to console dave bean Programming 1 02-21-2005 06:44 AM
how to manipulate string in script? ringerxyz Programming 2 02-17-2005 01:14 AM
Manipulate .ISO files in Linux????? Garrett_80 Linux - Software 3 12-15-2004 09:53 AM


All times are GMT -5. The time now is 07:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration