Sponsored Content
Top Forums Shell Programming and Scripting unix script to check whether particular file exists and to find its size Post 302164473 by Balachandar on Tuesday 5th of February 2008 02:09:11 AM
Old 02-05-2008
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check File Exists and compare to previous day file script

We have data files that are ftp'd every morning to a SUN server. The file names are exactly the same except for that each has the date included in its name. I have to write script to do 2 things: STEP 1) Verify that the file arrived in morning. STEP 2) Compare the file size of the current... (3 Replies)
Discussion started by: rbknisely
3 Replies

2. Shell Programming and Scripting

Need to write a script in UNIX to find a file if another file exists

So I have a lot of Java applications on my servers all having their own folder from the applications subdirectory. Now, I need to do the following. Search all the applications subdirectories for message.jar. If the message.jar file exists, I need to search the application directory for... (1 Reply)
Discussion started by: mmdawg
1 Replies

3. Shell Programming and Scripting

Command/script to find size of Unix Box ?

Please could anyone provide me the Command/script to find the size and usage of Unix box ASAP ? (6 Replies)
Discussion started by: sakthifire
6 Replies

4. UNIX for Advanced & Expert Users

how to find the file size in unix

Anybody can help HOW TO FIND THE FILE SIZE IN UNIX (5 Replies)
Discussion started by: lmraochodisetti
5 Replies

5. Shell Programming and Scripting

Shell script to check if any file exists in 4 folders

Hi All, working on AIX 5.3. Requirement is: Shell script in ksh to check if any file exists in 4 folders as below: 1. /FILE/INB/INT1 2. /FILE/INB/INT2 3. /FILE/INB/INT3 4. /FILE/INB/INT4 Thanks a lot for your time! a1_win. (3 Replies)
Discussion started by: a1_win
3 Replies

6. Shell Programming and Scripting

Script to check if file exists

guys, I am trying to write a script that does the following: it looks for a file in a specific directory and if the file is not there (NOT), it emails me. I have tried the following but its not working. It simply hangs up. Please help. if then mail -s 'blah blah blah' my email... (4 Replies)
Discussion started by: basisvasis
4 Replies

7. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

8. Shell Programming and Scripting

Script to check file exists

Hi, I am trying to write a script which checks if any file exists with "*.log" or "*.out" in Directory below is the code #------------------ path=/abd/xyz/ if ; then echo "Good" else echo "Failure" fi #-------------------------- its always going to else part and printing... (8 Replies)
Discussion started by: ch33ry
8 Replies

9. Shell Programming and Scripting

Except script fails to check file exists or not in remote node

Dear members, The following expect script connects to remote node and check for the file "authorized_keys" in directory /root/.ssh in remote node. However the result is always found even if the file exist or doesn't exist. expect { "$fname" { send_user "found\n" } Any idea what is... (4 Replies)
Discussion started by: Sudhakar333
4 Replies

10. Shell Programming and Scripting

Shell script which will check the target file and folder exists and copy it

Hi All, I am a beginner in this and trying to write a shell script in linux which will : 1. Ask for a file name and check if its exists. 2. If file exists only then it will ask for the new target folder, after entering target folder name it will check if it exists. 3. If target folder... (3 Replies)
Discussion started by: ashish_neekhra
3 Replies
print(1)							   User Commands							  print(1)

NAME
print - shell built-in function to output characters to the screen or window SYNOPSIS
ksh print [ -Rnprsu [n]] [arg...] DESCRIPTION
ksh The shell output mechanism. With no flags or with flag - or -, the arguments are printed on standard output as described by echo(1). OPTIONS
The following options are supported: -n suppresses new-line from being added to the output. -R -r (raw mode) ignore the escape conventions of echo. The -R option will print all subsequent arguments and options other than -n. -p causes the arguments to be written onto the pipe of the process spawned with |& instead of standard output. -s causes the arguments to be written onto the history file instead of standard output. -u [ n ] flag can be used to specify a one digit file descriptor unit number n on which the output will be placed. The default is 1. EXIT STATUS
The following exit values are returned: 0 Successful operation. >0 Output file is not open for writing. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
echo(1), ksh(1), attributes(5) SunOS 5.10 15 Apr 1994 print(1)
All times are GMT -4. The time now is 11:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy