SUMMARY: Checking a file for its directory

From: Robert K <unixrobert_at_yahoo.ca>
Date: Wed Jun 28 2006 - 14:05:28 EDT
Hello Managers
  I have received various solutions which will give the same output. Now my script is working as desired.
   
  Hudes, Dana 
  Suggested to  use / build upon logrotate instead of rolling my own.
   
  JV711
  echo $PWD or `basename` 

Deiter Scott
find /*/oradata/unitym/export/ -name "fullexport*.log" -mtime 0 -exec rm {} \;

  Sanjiv K.Bhatia
  find $LOG_DIR -name $1 -exec rm {} \;
   
  dersmythe
  if [ -w $LOG_DIR/$1 ]
  then
 rm $LOG_DIR/$1
  else
     echo "The file $1 is not under $LOG_DIR"
  fi
   
  David Breneman
  if [ -f $LOGDIR/$1 ]
then
 rm -f $LOGDIR/$1
else
 echo "The file $1 is not under $LOG_DIR"
fi
   
  Catlin, Brian
  If [ ! -f ${LOGDIR}/${FILE} ]
then
   whatever
fi

  Shaw, Kevin
  Suggested  to look at /usr/lib/newsyslog and see if it has lines I can use
   
  Truhn, Chad (Works only for BASH script)

if [ -a $LOG-DIR/$1 ] ; 
then
....
else
....
fi
   
  Bonfieti Junior, Angelo
  if [ !-f $LOG_DIR/$1 ]
  then
    echo "File $1 does not exists in $LOG_DIR"
  else
    rm $LOG_DIR/$1
fi

John Leadeham
  if [[ "$1" <is not under> "$LOG-DIR" ]]
 then
echo "The file $1 is not under $LOG_DIR ]]
else
  rm $1
  fi
   
  Brewer, Dwight R. CONTRACTOR
  if [ -s $LOG-DIR/$1 ]
then
   rm $LOG-DIR/$1
else
   echo "The file $1 is not under $LOG-DIR"
fi
   
  Brad_Morrison
  Suggested to use awk to split the components,concatenate,then index compare or some thing.
   
  Lineberger, Aaron (Stands good for ksh)
  cd $LOG_DIR
if [[ ! -e $1 ]]
then
   echo "$1 is not in ${LOG_DIR}, hoser."
fi 
  Thomas M. Payerle
  PATH=$1
FILE=`basename $PATH`
if [ "$LOGDIR/$FILE" = "$PATH" ]
then
  echo "is under LOGDIR"
fi
   
  thorsten.mueller
  if [ -f $LOG_DIR/$1 ]; then 
 # actions to do when file is present
 echo "present"
else
 # actions to do when file is not present
 echo "absent"
fi
the "-f" is the short version for the "test" command; -f checks for the 
presence of a file and " ! -f " is the negotiation.

  blg
  #!/bin/sh

# I take LOG_DIR from the command line too
LOG_DIR=$2

if [  ! -f "$LOG_DIR"/"$1" ] ; then
         echo "no $1 under $LOG_DIR"
else
         echo "$1 found under $LOG_DIR"
fi

Eric Voisard
#!/bin/sh

LOG_DIR=/var/log

if [ `dirname $1` != $LOG_DIR ]; then
        echo Not in $LOG_DIR
else
        echo Deleting $1
 rm $1
fi

  Dave Markham
  if [ -r "$log-dir/$1 ]
then
    rm $log-dir/$1 2>&1
else
    echo "The files [$1] is not under $log_dir\n"
fi

That will check for readable file. We can also check and only remove
if the logfile is above 0 bytes with -s.

Also suggested to consider a config file with different log files in perhaps
of which we could do in a loop :-

for x in `cat $logfiles.conf`
do
    if [ -r "$log-dir/$x"
    then
       .......
    fi
done

  James Ray
  if [ ! -e ${LOG_DIR}/$1 ]; then
 echo "The file $1 doesn't exist under ${LOG_DIR}"
else
 rm ${LOG_DIR}/$1
fi
   
  Thanks for all your help.
   
  Rob






  


 
   
   

Note: forwarded message attached.

 		
---------------------------------
All new Yahoo! Mail  
---------------------------------
Get news delivered. Enjoy RSS feeds right on your Mail page.
X-Apparently-To: unixrobert@yahoo.ca via 66.163.179.89; Tue, 27 Jun 2006
  12:47:19 -0700
X-Originating-IP: [128.100.17.250]
Authentication-Results: mta165.mail.re2.yahoo.com from=yahoo.ca;
  domainkeys=neutral (no sig)
Received: from 128.100.17.250  (EHLO sunportal.sunmanagers.org)
  (128.100.17.250) by mta165.mail.re2.yahoo.com with SMTP; Tue, 27 Jun
  2006 12:47:17 -0700
Received: from sunportal.sunmanagers.org (localhost [127.0.0.1]) by
  sunportal.sunmanagers.org (Postfix) with ESMTP id 4D9821E563; Tue, 27
  Jun 2006 15:13:05 -0400 (EDT)
X-Original-To: sunmanagers@sunmanagers.org
Delivered-To: sunmanagers@sunmanagers.org
Received: from web35213.mail.mud.yahoo.com (web35213.mail.mud.yahoo.com
  [66.163.179.92]) by sunportal.sunmanagers.org (Postfix) with SMTP id
  402791E563 for <sunmanagers@sunmanagers.org>; Tue, 27 Jun 2006
  15:12:51 -0400 (EDT)
Received: (qmail 68316 invoked by uid 60001); 27 Jun 2006 19:12:42 -0000
Received: from [209.135.74.2] by web35213.mail.mud.yahoo.com via HTTP;
  Tue, 27 Jun 2006 15:12:42 EDT
Date: Tue, 27 Jun 2006 15:12:42 -0400 (EDT)
From: Robert K <unixrobert@yahoo.ca>
Subject: Checking a file for its directory
To: sunmanagers@sunmanagers.org
MIME-Version: 1.0
X-Converted-To-Plain-Text: from multipart/alternative by demime 1.01b
X-Converted-To-Plain-Text: Alternative section used was text/plain
X-BeenThere: sunmanagers@sunmanagers.org
X-Mailman-Version: 2.1.8
Precedence: list
List-Id: The Sun Managers Mailing List <sunmanagers.sunmanagers.org>
List-Unsubscribe: <http://www.sunmanagers.org/mailman/listinfo/sunmanagers>,
  <mailto:sunmanagers-request@sunmanagers.org?subject=unsubscribe>
List-Archive: <http://www.sunmanagers.org/pipermail/sunmanagers>
List-Post: <mailto:sunmanagers@sunmanagers.org>
List-Help: <mailto:sunmanagers-request@sunmanagers.org?subject=help>
List-Subscribe: <http://www.sunmanagers.org/mailman/listinfo/sunmanagers>,
  <mailto:sunmanagers-request@sunmanagers.org?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: sunmanagers-bounces@sunmanagers.org
Errors-To: sunmanagers-bounces@sunmanagers.org
Content-Length: 552

Hello Managers
  I am writing a script to delete logfiles. The script will be called at the command line followed by the log file name as the argument. Right now I am working for <./scriptname> <filename>. I have added couple of "if-then-*-fi"s
  to check for root access and the sake of one file name as the command line argument. Now I also want to add one more loop which will be perforfmed after the above mentioned loops that checks whether the file is under the LOG_DIR (This is a declared variable at the begining of the script) or not?
   
  Basically I want the command or syntax for this.
   
  if [[ "$1" <is not under> "$LOG-DIR" ]]
  then
  echo "The file $1 is not under $LOG_DIR ]]
  else
  rm $1
  fi
   
  Thanks and I will summarize

 		
---------------------------------
 All new Yahoo! Mail - 
---------------------------------
Get a sneak peak at messages with a handy reading pane.
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Wed Jun 28 14:05:53 2006

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:59 EST