The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-17-2006
Registered User
 

Join Date: Jan 2006
Posts: 7
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.
Reply With Quote
Forum Sponsor
  #2  
Old 01-18-2006
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
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
Reply With Quote
  #3  
Old 01-18-2006
Registered User
 

Join Date: Jan 2006
Posts: 7
cheers ill try that next week, going on holiday and no comp going with me. ill let you know how it goes
Reply With Quote
  #4  
Old 01-23-2006
Registered User
 

Join Date: Jan 2006
Posts: 7
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
signofffiles is the directory where the signofffiles are kept (to be changed when in production) but i am not sure if it is actually going into the direcotry
that i require

this is set as following
Code:
signofffiles=/home/nzbt6t/signoff/filedownload
the file name structure is scan.batchno.[SC].03.[YEARMONTHDAY].signed.off at this stage the date doesnt really matter but it may do.

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
Reply With Quote
  #5  
Old 01-24-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
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
Reply With Quote
  #6  
Old 01-24-2006
Registered User
 

Join Date: Jan 2006
Posts: 7
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
Ok i have this... There is just something wrong with the if statement. but other than that it is working. the if statement is always picking up that there is something in $1. For example if the file is not there $1 is

Code:
/home/nzbt6t/signoff/filedownload/scan.batchno.CH.03.[0-9]*.signed.off
if a file is there, and i can see it it still comes out that the file is absent all the time. can anyone see anything really obvious about this? i am sure there is.

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
btw thanks so much for your help so far i can feel i am so close. if it is was in vb it would be so simple
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0