![]() |
|
|
|
|
|||||||
| 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 timestamp on specific files | grinds | Shell Programming and Scripting | 2 | 05-16-2008 12:01 PM |
| check position of end of line for some specific lines | senthil_is | Shell Programming and Scripting | 1 | 11-08-2007 10:19 PM |
| Moving specific files | Stud33 | Shell Programming and Scripting | 4 | 03-31-2007 06:50 PM |
| tar subdirectories for specific files | ronald_brayan | UNIX for Advanced & Expert Users | 4 | 10-12-2006 02:53 AM |
| How to check for specific process running through shell | agp | Shell Programming and Scripting | 3 | 03-25-2006 03:24 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Check for specific files
Ok, i have a problem and not sure how to tackle this one as of yet.
I will have this job running in the cron every 5 minutes, i need it to check a directory for 5 files. These files are put into a directory from five different servers. These 5 files will only have one part different in them, and that is what server they have come from. I need to check for these different files. I have put the file names into an array from a parameter file and just need to check them. the rest of the filename is just the date that the file was created. is there an easy way to check a directory for the files, and check that each server has sent a file? there could be more than these 5 files in this one directory but they all have the extention .signed.off once these 5 files are in there i have another process written for it to do something with these 5 files, so thats no problem (atm) um.. i hope this makes sense. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
You could try using a loop to check the presence of each file, e.g....
Code:
for i in server_one server_two etc
do
set *${i}.signed.off
if [[ $# -eq 1 ]] && [[ -s $1 ]]
then
echo file from server $i is present, file name is $1
else
echo file from server $i is absent
fi
done
|
|
#3
|
|||
|
|||
|
cheers ill try that next week, going on holiday and no comp going with me. ill let you know how it goes
|
|
#4
|
|||
|
|||
|
ok, i have a small question.
just what does if [[ $# -eq 1 ]] && [[ -s $1 ]] do? i am a bit new, and its not quite doing what i am askign it to do. i have an array of 5 items (0 -4) but this could change so i need it to go for each array (called SC) I have it going through 5 times now using a while loop Code:
i=0
while (( i < ${#SC[*]}))
do
set $signofffiles/*${i}*.signed.off
if [[ $# -eq 1 ]] && [[ -s $1 ]]
then
echo file from server $i is present, file name is $1
else
echo file from server $i is absent
fi
((i = i + 1))
done
that i require this is set as following Code:
signofffiles=/home/nzbt6t/signoff/filedownload at the moment it is saying the files are absent when i have put them in there manually. can anyone see what i have done to make it not work? i am sure somoene can. cheers all for looking at my problem as well |
|
#5
|
||||
|
||||
|
set $signofffiles/*${i}*.signed.off
Generate file list and assign to positinal parameters $1 ... if [[ $# -eq 1 ]] && [[ -s $1 ]] Test if one not empty file found Code:
i=0
while (( i < ${#SC[*]}))
do
set $signofffiles/scan.batchno.${SC[$i]}.03.[0-9]*.signed.off
if [[ $# -eq 1 && -s $1 ]]
then
echo file from server $i is present, file name is $1
else
echo file from server $i is absent
fi
((i = i + 1))
done
|
|
#6
|
|||
|
|||
|
Code:
i=0
while (( i < ${#SC[*]}))
do
set $signofffiles/scan.batchno.${SC[$i]}.03.[0-9]*.signed.off
if [[ $# -eq 1 && -s $1 ]]
then
echo file from server $i is present, file name is $1
else
echo file from server $i is absent
fi
((i = i + 1))
done
Code:
/home/nzbt6t/signoff/filedownload/scan.batchno.CH.03.[0-9]*.signed.off using echo $1 and echo $# as well as the output i am getting the following: Code:
/home/nzbt6t/signoff/filedownload/scan.batchno.EL.03.20060119.signed.off 1 file from server 0 is absent /home/nzbt6t/signoff/filedownload/scan.batchno.HN.03.20060119.signed.off 1 file from server 1 is absent /home/nzbt6t/signoff/filedownload/scan.batchno.VV.03.20060119.signed.off 1 file from server 2 is absent /home/nzbt6t/signoff/filedownload/scan.batchno.CH.03.[0-9]*.signed.off 1 file from server 3 is absent /home/nzbt6t/signoff/filedownload/scan.batchno.DN.03.20060119.signed.off 1 file from server 4 is absent |
|||
| Google The UNIX and Linux Forums |