![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 07: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 09:44 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
unix script to check whether particular file exists and to find its size
I want to find the size of particular file exists in a particular directory
and i wnt to zip it. In the below mentioned code it should check the MQ.log in the particular directory.Please correct my code so that it will check for particular MQ.log but i could not able to check whether the MQ.log exist and please tell me the way to check the file size also ROTATE_FILES="/apps/Mesa/Logs/AE/AE_logs/test" REAL_FILE="MQ.log" function rotate_files() { for j in $1;do 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}'` $LIMIT = 0 if [ $i -ge 0 ];then echo "the size is greater" fi fi done fi done } rotate_files "$ROTATE_FILES" Last edited by Balachandar; 02-04-2008 at 02:32 AM. |
| Forum Sponsor | ||
|
|
|
|||
|
if [[ -e $filename ]];then
echo "file exists" fi or to check if its a file not a dir then if [[ -f $filename ]];then echo "its a simple file" fi if you are taking as command line arguements replace $filename with $1,if it is the firsta rguement. filesize=`ls -l sample_file |awk '{print $5 }'` echo $filesize |
|
|||
|
Quote:
Code:
find /dir -type f -name "myfile" -size +0 -exec gzip <fill in the blank> {} \;
|
|
|||
|
Hi Balchander
I think you can do it this way 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}'` LIMIT=0 if [ $FILESIZE -ge 0 ] then echo "the size is greater" fi fi done fi done } rotate_files "$ROTATE_FILES" |
|
|||
|
bug in checking the file size
Thanks infyanurag and all
the code works fine but i still get some bugs....... Its printing the loop1 and MQ.log but when it goes to checking the file size it throws error...... "ls: MQ.log: No such file or directory" ......... and also in the braces which suppose to check the file size greater than zero Inside the script 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 -------------------------------------- Loop1 MQ.log ls: MQ.log: No such file or directory test4.sh: line 21: [: -ge: unary operator expected ------------------------------------------- please correct me Last edited by Balachandar; 02-04-2008 at 05:25 AM. |
|||
| Google The UNIX and Linux Forums |