script to check files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to check files
# 1  
Old 10-01-2008
script to check files

I have a set of files in a folder, I need a script which basically checks whether each file is present or not and if any one of them is missing , the script should fail (exit out) displaying the name of the file which does not exist .
this is the list of files
insert_dma_prspct_daily_tmp.sql
t_prspct_cntct_daily_tmp_dedup_CARI.sql
t_prspct_cntct_daily_tmp_dedup_CARI.sql
t_prspct_cntct_daily_tmp_copy_prspct_id.sql
t_prspct_cntct_daily_tmp_delete_reload.sql
t_raprspct_hdr_daily_tmp_insert.sql
t_ra_prspct_match_ref_truncate.sql
check_reactive_cnt.sql
t_prspct_cntct_daily_tmp_update.sql
t_prspct_cntct_daily_dup_PID_update.sql
t_prspct_cntct_daily_tmp_dedup.sql
delete_dup_prspct_daily_tmp.sql
t_reactive_prspct_insert.sql
t_prspct_cntct_non_accept_delete.sql
process_old_response.sql
t_current_prspct_response_update.sql
t_prspct_cntct_hist_log_insert.sql
t_prspct_cntct_hist_update.sql
t_choice_volunteer_insert.sql
t_choice_bus_volunteer_insert.sql
t_volunteer_update.sql
t_bus_volunteer_update.sql
t_bus_volunteer_hist_mtl_insert.sql
t_bus_volunteer_mtl_delete.sql
t_choice_bus_volunteer_mtl_insert.sql
t_bus_volunteer_update.sql
t_prspct_sales_agent_update.sql
# 2  
Old 10-01-2008
Assuming list of files is in a file called "file_list".

cat file_list|while read F
do
if [ -f $F ]
then
echo "Missing: $F"
fi
done


This finds all the missing files. If you want to stop after the first error, put an "exit" or a "break" after the "echo".
# 3  
Old 10-01-2008
but if its missing it should come out of the loop ...the loop should not move ahead

but if its missing it should come out of the loop ...the loop should not move ahead
# 4  
Old 10-01-2008
if you have PHP
Code:
<?php

$list_of_files = "file";
$handle = fopen($list_of_files,"r");
while (!feof($handle)) {
    $file = trim(fgets($handle,4096 ));
    if ( !file_exists($file) ){
        echo "File: $file does not exists\n";
        break;
    }
}
fclose($handle);
?>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script to check if files are being sent

SunOS -s 5.10 Generic_147440-04 sun4u sparc SUNW,SPARC-Enterprise Hi, on one system there are folders which are being created based on today's date /data/CDR/sswitch_roa/voice/bkup/<yyyymmdd> (e.g /data/CDR/sswitch_roa/voice/bkup/20180620 – is the path for today’s... (1 Reply)
Discussion started by: roshanbi
1 Replies

2. UNIX for Beginners Questions & Answers

Script to check if files exits

Hi In live system core files are generating frequently. around 10 core files in 30 mins in root file system. which is eating my space very much below is core file core.56539 core.78886 core.12302 core.80554 core.20147 I am trying to write a script which should move... (7 Replies)
Discussion started by: scriptor
7 Replies

3. Shell Programming and Scripting

Shell script to check a file and delete old files

Hello, I needed help with a shell script where in it checks if a file exists under a directory and also checks the age of the file and delete it if it is older than 3 weeks. thanks (10 Replies)
Discussion started by: hasn318
10 Replies

4. Shell Programming and Scripting

Bash script for check files

I created this script for check whether specific files exist or not in the given location. but when I run this its always showing Failed - Flag_lms_device_info_20160628.txt do not exist Failed - Flag_lms_weekly_usage_info_20160628.txt do not exist but both files are existing. appreciate help... (2 Replies)
Discussion started by: lfreez
2 Replies

5. Shell Programming and Scripting

Shell/perl script to check for files

Hi, I am trying to write a script for following scenario: I have a list of countries from where I receive files...eg. (Indonesia, Thailand, Australia...etc) For each country, I have a list of files that they send. IND -- a,b,c TH -- p,q,r AU -- x,y,z The path for these files could... (2 Replies)
Discussion started by: neil.k
2 Replies

6. Shell Programming and Scripting

Script to check files ownership

Hi All, I wanted to check the files ownership and permission based on the path given it as arguments thru script. I was able to get the required command using ls but i would like this command to put in a script and check the file ownership against the what it needs to be and report back if... (12 Replies)
Discussion started by: Optimus81
12 Replies

7. Shell Programming and Scripting

How to check whether directory has files in it or not in shell script?

hi, I am having script in which i want to check if directory has any file in it or not. If directory contains a single or more files then and only then it should proceed to further operations... P.S.: Directory might have thousand number of files. so there might be chance of getting error... (4 Replies)
Discussion started by: VSom007
4 Replies

8. Shell Programming and Scripting

need a shell script to extract the files from source file and check whether those files existonserve

Hi, I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is # echo $0 -sh My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether... (13 Replies)
Discussion started by: muraliinfy04
13 Replies

9. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

10. Shell Programming and Scripting

Need a script to copy files and check

Hi all, I need a script in ksh: 1: Copy files from directory (A) to directory (B) 2: Check if files that will be copied in directory (A) have never been yet copied to (B) 3: Never copy the last created file of directory (A) This script will run on crontab. Thanks in advance for your... (1 Reply)
Discussion started by: Camaro
1 Replies
Login or Register to Ask a Question