The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
check if remote file exists hcclnoodles Shell Programming and Scripting 2 08-27-2008 02:53 PM
Need to write a script in UNIX to find a file if another file exists mmdawg Shell Programming and Scripting 1 05-04-2008 07:40 PM
Check File Exists and compare to previous day file script rbknisely Shell Programming and Scripting 3 02-07-2008 08:53 AM
Need Script to check whether user exists in the remote machine Srini75 SCO 1 09-07-2005 08:23 AM
file exists and size greater that zero methos Shell Programming and Scripting 3 03-25-2002 10:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 02-05-2008
Registered User
 

Join Date: Feb 2008
Posts: 4
compile time error when i execute this code

Hi all,
Please tell me to solve this issue,

ROTATE_FILES=" <PATH>"
REAL_FILE="MQ.log"

function rotate_files()
{
for j in $1;do
echo "Loop1"

if [ -d $j ]
then
for i in `ls -a /$j`
do

if [ $i = MQ.log ]
then
echo $i

FILESIZE=`ls -l $i|awk '{print $5}'` #......error......#
LIMIT=0

if [ $FILESIZE -ge 0 ] #......error......#
then
echo "the size is greater"
fi

fi

done
fi
done
}

rotate_files "$ROTATE_FILES"

-----------------------------------------------------------------

FILESIZE=`ls -l $i|awk '{print $5}'`
"ls: MQ.log: No such file or directory" <<<error message

if [ $FILESIZE -ge 0 ]
"[: -ge: unary operator expected" <<<error message

please tell me how to solve this
Reply With Quote
Forum Sponsor
  #9  
Old 02-05-2008
Registered User
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Try providing full path instead of relative path

Quote:
FILESIZE=`ls -l $i|awk '{print $5}'` #......error......#
In case the script is executed from the different directory,then "$i" will expand to MQ.log and not the full path to it,so it throws an error.Either you can try running the script from the directory (ROTATE_PATH) or give the full path

Thanks
Nagarajan G
Reply With Quote
  #10  
Old 02-05-2008
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 288
Quote:
Originally Posted by Balachandar View Post
Hi all,
Please tell me to solve this issue,

ROTATE_FILES=" <PATH>"
REAL_FILE="MQ.log"

function rotate_files()
{
for j in $1;do
echo "Loop1"

if [ -d $j ]
then
for i in `ls -a /$j`
do

if [ $i = MQ.log ]
then
echo $i

FILESIZE=`ls -l $i|awk '{print $5}'` #......error......#
LIMIT=0

if [ $FILESIZE -ge 0 ] #......error......#
then
echo "the size is greater"
fi

fi

done
fi
done
}

rotate_files "$ROTATE_FILES"

-----------------------------------------------------------------

FILESIZE=`ls -l $i|awk '{print $5}'`
"ls: MQ.log: No such file or directory" <<<error message

if [ $FILESIZE -ge 0 ]
"[: -ge: unary operator expected" <<<error message

please tell me how to solve this
change -ge to -gt

check if [[ ! -f $i ]];then
only check the size.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0