Scripting to check the size of file and it's existance.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting to check the size of file and it's existance.
# 1  
Old 06-06-2011
Scripting to check the size of file and it's existance.

Hi,
I am totaly new to create a script . Please help.

I have file name retrived from SAP table into a internal table .
Like :-
Code:
/home/td_8d02_int_data_IPCL/ILLUSTRATIONS/CGM/l_pc_112138_01_0_01_00.cgm
/home/td_8d02_int_data_IPC-L/ILLUSTRATIONS/CMP/l_pc_112138_01_0_01_00.cmp

Objective :-
1) To check the above file size of file and it's existance on unix
2) For this we have to create a Script in SAP directory consisting of detail of above files , with unix code that will run on unix and check it's file size first and then it's existance.

Analysis :-
Loop at SAP_internal_table into variable lw_file

Code:
( lw_file 
/home/td_8d02_int_data_IPC-L/ILLUSTRATIONS/CGM/l_pc_112138_01_0_01_00.cgm

)


******************Now from here the creation of scripting starts*********************** ( Need your help in this )

Code:
#!/bin/ksh    
 
let nb_error = 0.
let nb_error_exist = 0.
 
Test -s  lw_file ( Please tell wether it is ok or not , we have to check the size of file greater than zero )
 
if [$? ! = "0"]
then
let nb_error = $ nb_error + 1

*************** Now here i want a internal table or array to store the file name only which is empty *************

Store the file name in a table1.

Code:
test -e lw_file ( Please tell wether it is ok or not , we have to check the existance of the file )

if [$? ! = "0"]
then
let nb_error_exist = $ nb_error_exist+ 1

*************** Now here i want a internal table or array to store the file name only which does not exist *************

Store the file name in a table2.


FI
FI

******Writing of script data
List of missing released illustrations ( *Constant value )

Loop on table1.
Write the file name.

List of missing released illustrations ( *Constant value )

Loop on table2.
Write the file name.


This will be the desired result :-
Code:
List of missing released illustrations
l_pc_291334_01_0_01_00.cmp
l_pc_441133_50_0_02_00.cmp
l_pc_441133_55_0_02_00.cmp
 
List of empty released illustrations
l_pc_534941_01_0_01_00.cmp
 
End of record


Last edited by pludi; 06-06-2011 at 06:47 AM..
# 2  
Old 06-06-2011
No idea about SAP. but the UNIX part goes something like this..

Code:
file=/home/td_8d02_int_data_IPC-L/ILLUSTRATIONS/CGM/l_pc_112138_01_0_01_00.cgm
[ -f $file ] && echo "$file exists and size is $(ls -l $file | awk '{print $5}')" || echo "$file does not exist."

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File size check

I am trying to check whether two files are empty or not using below if condition but its checking for only one file if ] Again I tried if && ] Need your assistance (2 Replies)
Discussion started by: Aditya_001
2 Replies

2. Shell Programming and Scripting

Csh/tcsh : Check the file existance and run the script

Hi, I've to wait until a file generated and once its generated, source another script in Linux terminal. Please help me as this is very very urgent. The code should be something like if ( -e "/abc/xyz/a.txt ) source aaa.csh else sleep This should be repeated till the if... (4 Replies)
Discussion started by: kumar_eee
4 Replies

3. Shell Programming and Scripting

Check a file size

I'm doing a script thats check if mylogfile.log is bigger then 5000 but i dont know how to write it. thanks in avance. (6 Replies)
Discussion started by: Froob
6 Replies

4. Shell Programming and Scripting

check for file existance and generate exit code amd move to another directory

Hi.. i have a file ABC_*.txt in source directory which will come evry 30 min and same file will be moved to working directory first time ...and will perform some operations then we archive ABC_*.txt ..this will run for 30 min to 45 min from 2nd time onwards requirement is ...i need to check... (3 Replies)
Discussion started by: dssyadav
3 Replies

5. Shell Programming and Scripting

how to check existance of multiple directories

Hi, I would like to check whether all the directories exists or not. I tried the below but it gives some error. below is the excerpt from my original script 24 #Check if the required directories are exists 25 dirExists() { 26 27 if 28 then 29 echo "required... (1 Reply)
Discussion started by: lookinginfo
1 Replies

6. Shell Programming and Scripting

check the file size

if ; then cp /tmp/testfolder/*.* ~/new/logs/ else echo "No files today" exit fi The problem is this doen't work when there is more than 1 file. Please tell me how to take the latest file and check the size of the file in a directory (1 Reply)
Discussion started by: sandy1028
1 Replies

7. Shell Programming and Scripting

Check the file size - help

I want to write a batch job (ksh) with the following requirement we have file feeds coming to our system from other team, if the file size is greater than expected then we dont need to process the file for the day and need to archive the file and send email notification to the manager saying... (5 Replies)
Discussion started by: sithara
5 Replies

8. Shell Programming and Scripting

Check for file size is zero or not.

I have following script on AIX/KSH if ] ; then echo "filename exists and is > 0 bytes" else echo "filename does not exist or is zero length" fi It is not working. What is wrong here??? (3 Replies)
Discussion started by: Hangman2
3 Replies

9. Shell Programming and Scripting

check the file existance

Hello, I have two files .. 1. inventory_i.txt 2. inventory_b.txt I want to check if these two files exists. If exists, then do the process, otherwise, quite... if ; then echo "exists" else echo " does not exists" fi The above logic is not working... It is always, displaying Does... (2 Replies)
Discussion started by: govindts
2 Replies

10. UNIX for Dummies Questions & Answers

Check file size

I need a unix script that will check the size of multiple files in the same directory or from a text file. (6 Replies)
Discussion started by: alnita
6 Replies
Login or Register to Ask a Question