Strange one (likely something simple...)

Right folks... this is probably something simple that I'm missing as it's early, but can anyone tell me what's going on here:

The Script:

cougar:/usr/hxscripts>vi ~/test.ksh
"/usr/home/branch/users/tech/test.ksh" [New file]
#!/bin/ksh

LOGDIR=/usr/hxscripts/LOGS/logmeoff/    # Logging directory, must be world-writable
RETDAYS=31               # Number of days to retain old logfiles


ME=`logname`            # Username
SCRIPT="logmeoff"       # Script name

# FUNCTIONS
###########


Log () {
set -x

##Construct the log file path and name##
LOGFILE=${LOGDIR}/${1}.`date +%a%d%b%y`.logmeoff.log

##Check whether today's logfile exists and create if not##
[ -w $LOGFILE ] ||  ( touch $LOGFILE; chmod 666 $LOGFILE )

##Delete logmeoff log files older than $RETDAYS old##
find $LOGDIR -type f -name '*.logmeoff.log' -mtime +$RETDAYS -exec rm {} \;

##Write the log entry##
echo "`date +%T`|`logname`|`who am i`" >> $LOGFILE

}


Log test

And the output:

cougar:/usr/hxscripts>ksh ~/test.ksh
+ + date +%a%d%b%y
LOGFILE=/usr/hxscripts/LOGS/test.Tue30Oct07.logmeoff.log
+ [ -w /usr/hxscripts/LOGS/test.Tue30Oct07.logmeoff.log ]
+ touch /usr/hxscripts/LOGS/test.Tue30Oct07.logmeoff.log
+ chmod 666 /usr/hxscripts/LOGS/test.Tue30Oct07.logmeoff.log
+ find /usr/hxscripts/LOGS -type f -name *.logmeoff.log -mtime +31 -exec rm {} ;
+ date +%T
+ logname
+ who am i
+ echo 09:06:26|tech|tech        pts/1374    30 Oct 08:53     (g10wshud311.zg.if.atcsg.net)
+ 1>> /usr/hxscripts/LOGS/test.Tue30Oct07.logmeoff.log
cougar:/usr/hxscripts>ls -ld /usr/hxscripts/LOGS/logmeoff/
drwxrwxrwx   2 tech     users           512 17 Oct 13:25 /usr/hxscripts/LOGS/logmeoff/

As you can see, even though I'm specifying that the LOGDIR is the existing and world-changable directory /usr/hxscripts/LOGS/logmeoff/, everything goes to /usr/hxscripts/LOGS. Why is this?!

Obviously this isn't causing me massive headaches, but I'd like to know what's going on!

Many thanks,

Alex

LOGDIR=/usr/hxscripts/LOGS/logmeoff/

Is the trailing slash needed as you add another when you concatenate?

No, I guess it isn't needed.

I just prefer to put it in when using directory paths in variables which I know are going to be used in such a way. That way you either end up with 'DIRECTORY/file', or 'DIRECTORY//file'. Rather than risking 'DIRECTORYfile'.

I didn't think that either mattered.

I suppose at this point I should mention I'm using ksh on AIX

Try changing the code a little bit:

#! /bin/ksh

LOGDIR="/home/Administrator/LOGS/logmeoff"    # Logging directory, must be world-writable
RETDAYS="31"               # Number of days to retain old logfiles


ME="$(logname)"            # Username
SCRIPT="logmeoff"       # Script name

# FUNCTIONS
###########


Log () {
set -x

##Construct the log file path and name##
LOGFILE="$LOGDIR"/"$1"."$(date +%a%d%b%y)".logmeoff.log

##Check whether today's logfile exists and create if not##
[ -w "$LOGFILE" ] ||  { touch "$LOGFILE"; chmod 666 "$LOGFILE"; }

##Delete logmeoff log files older than $RETDAYS old##
find "$LOGDIR" -type f -name '*.logmeoff.log' -mtime +"$RETDAYS" -exec rm {} \;

##Write the log entry##
printf "%s\n" "$(date +%T)|$ME|$(who am i)" >> "$LOGFILE"

}

Log test

oopss....

I've been a little stupid on this one.

Thanks for your input Porter and Radoulov. Radoulov - I see what you're getting at there with all the quoting variables. Whilst it might be a good habit I don't think it would have made much difference in this instance.

There was a part of the script that I had cut out - it's a standard thing we chuck in our scripts which assigns a load of useful variables - including LOGDIR. It was overwriting it with /usr/hxscripts/LOGS - it just didn't occur to me that this might happen. Oops.

Sorry to waste your time, folks!

Thanks again.

-Alex

Yes, it's just a good habit ...