verifying existence of multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting verifying existence of multiple files
# 1  
Old 11-29-2007
verifying existence of multiple files

Hi,

I have unix script on solaris 5.10.

I have to verify existence of 3 files in path and sleep for 1 hour.

I have tried for 1 file:

if [ -f /path/filename ]

then

echo " File is found!"

sleep 3600
echo "time delayed"

fi

Please advice
# 2  
Old 11-29-2007
Why not use a cron job that is run every hour and then checks the files?
# 3  
Old 11-30-2007
I don't have any idea about cron job Smilie

Can i use something like :

#!/usr/bin/ksh
if [ -f /path/file1 and -f /path/file2]

then

echo " File is found!"

sleep 300
echo "time delayed"

fi

Last edited by ammu; 11-30-2007 at 10:42 AM..
# 4  
Old 11-30-2007
how about

#!/bin/ksh
until [[ 1 -gt 2 ]]; do # infinite loop
status="found" # default to true
for i in file1 file2 file3; do
if [ ! -f $i ]; then
status="not found" # if one or more of the files doesn't exist set to false
fi
done
echo Files are ${status}.
sleep 5
done
# 5  
Old 11-30-2007
if your requirement is to sleep for a defined time, only if ALL files exist:
in a ksh shell

Code:
 ( [[ -f file1 ]]; [[ -f file2 ]]; [[ -f file3 ]] )  && ( sleep 30;echo all files found ) || echo one or more files not found

# 6  
Old 11-30-2007
Thank you Smilie

It is working
# 7  
Old 11-30-2007
checking file

i have create one dir that have 3 files and my following script keep checking those file in every 10 sec

#!/usr/bin/ksh
DD=`date`
while :;
do
if [ -f ./tmp/tmp1.tmp -a -f ./tmp/tmp2.tmp -a -f ./tmp/tmp3.tmp ]; then

echo "File Exist $DD " >> ./log.tmp

else

echo "One of File Not exist $DD" >> ./log.tmp
fi
sleep 10
done

but i guess you need another script to kick of this script so if you even log off your machine it won't affect your script

#!/usr/bin/ksh

nohup ./file_check.ksh &

this script will kick off the file_check.ksh and terminate and it will keep record the log in the nohup.out and log.tmp

I hope this might help you out.

Thanks
Soni
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check the Files existence

Hi I have a requirement to check whether the files exists, then it will call other steps in shell script. I did ls *.csv|wc -l if then checking the count of the files should be more than 1 then it will call other steps. I am getting the error that too many arguements as there n... (13 Replies)
Discussion started by: cnrj
13 Replies

2. Shell Programming and Scripting

Check for the existence and add them from 2 different files

Hi, I have two files file1: ALEX DANY GARY TOM MARY HARRIS file2: ALEX 3 ALEX 5 ALEX 0 ALEX 1 ALEX 0 DANY 2 (2 Replies)
Discussion started by: Diya123
2 Replies

3. Shell Programming and Scripting

check existence of files in a folder

Hi I am having a problem to verify existence of files. I need to know whether or not files in a folder that begins with a name. For example all files that start with The_File_ *. I was doing it this way, but gives me error. if text -f /work/The_File_* then ... else .. fi (5 Replies)
Discussion started by: Rodrih92
5 Replies

4. Shell Programming and Scripting

test for existence of files with same extension

Hi, I am checking for existence of files with the same extensions #! /usr/bin/ksh txtfiles = '*.txt' if then cp ${dirpath}/${txtfiles} ${dir2path} fi I am getting the following error line 5: [: too many arguments for the if check condition (4 Replies)
Discussion started by: chen.sara
4 Replies

5. Shell Programming and Scripting

replace multiple existence of : symbol with one

Infile Outfile (3 Replies)
Discussion started by: dvah
3 Replies

6. Shell Programming and Scripting

Test for existence of files

Hello, Can you please help me to see if log files exist in a directory? I need to scan logs in different directories, so I am using an array to change dynamically. I need help in the if test statement dir=/logs/MSD dir=/logs/UPD countA=1 while (( countA <= ${#dir } )) do cd ${dir}... (1 Reply)
Discussion started by: drbiloukos
1 Replies

7. Shell Programming and Scripting

Script needed to wait for existence of multiple files

Hi Forum. I need a script to wait for all multiple trigger files to be present or else go to sleep for 10 seconds (Number of trigger files can vary). I tried to search on the forum but was not able to find a solution. I found this code on this forum but it's not working as expected: for... (6 Replies)
Discussion started by: pchang
6 Replies

8. UNIX for Dummies Questions & Answers

Tests for existence of files/directories

Hi, - The first question I have concerns a very fundamental aspect of a unix OS. Specifically, does unix treat everything as a file (ie a directory is just a type of file)? - The reason I ask is that I am trying to determine which BASH unary operator I would to use to determine whether or not... (1 Reply)
Discussion started by: msb65
1 Replies

9. Shell Programming and Scripting

Checking Multiple file existence

Hi, I want to check multiple files exist or not in a single if statement in korn Shell:confused:. Please help me Thanks (1 Reply)
Discussion started by: lathish
1 Replies

10. Shell Programming and Scripting

check for FILES existence

hi, I have a list of filenames and I want to verify if they all exist. I know "if filename" would do the trick but how do I go about a list of files? thanks (3 Replies)
Discussion started by: mpang_
3 Replies
Login or Register to Ask a Question