Check for specific files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check for specific files
# 1  
Old 01-18-2006
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.
# 2  
Old 01-18-2006
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  
Old 01-19-2006
cheers ill try that next week, going on holiday and no comp going with me. ill let you know how it goes
# 4  
Old 01-23-2006
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
# 5  
Old 01-24-2006
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  
Old 01-24-2006
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 Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check first specific string after a pattern

Hi, I've a file with content as below first_block_list{ a:5 b:3 c:8 } new_store_list( a:1000 b:200 c:3343 ) first_item_list{ a:10 b:20 c:30 } second_item_list{ (1 Reply)
Discussion started by: ratheeshp
1 Replies

2. UNIX for Dummies Questions & Answers

Check for entry of specific pattern

Hey Guys and Gals, I am having trouble with what I thought shouldn't be hard.. In a script I am working on there is a need to enter a MAC address. MAC addresses are formatted ; XX:XX:XX:XX:XX:XX where X can be 0-9, a-f or A-F So in the sample script the query is something... (4 Replies)
Discussion started by: TAPE
4 Replies

3. Shell Programming and Scripting

Check for Specific Username Password Expire

hey Guys, I haven't posted in a while, But you guys were really helpful alst time. I have had a issue with User Passwords expiring, and since I dont check /var/cron/log on the regular I never know these suers are expiring, making certain nightly jobs not run. With this script, I want to be... (14 Replies)
Discussion started by: gkelly1117
14 Replies

4. Shell Programming and Scripting

Perl code to check date and check files in particular dir

Hi Experts, I am checking how to get day in Perl. If it is “Monday” I need to process…below is the pseudo code. Can you please prove the code for below condition. if (today=="Monday" ) { while (current_time LESS THAN 9:01 AM) ... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies

5. Shell Programming and Scripting

Request to check:count specific entries

Hi all I have an input file which contains so many entries like this: And, I want to count hw many among ASN in one column are converted to LYS in third coulmns. which means output shuld contain only "ASN number LYS" Kindly let me know wny programm for this My input is ASN 217 LYS... (2 Replies)
Discussion started by: manigrover
2 Replies

6. Shell Programming and Scripting

Check a specific word whether is in file

I want to valid a specific word whether it is contained in the text file. For example: family.txt father mother son sister if ("father" contain in family.txt) do some process else do other process How shell scripting can accomplish this? Anyone can provide helps? (3 Replies)
Discussion started by: alvin0618
3 Replies

7. Shell Programming and Scripting

How to check for a specific process running or not in Unix

I have used ps -ef | grep <process name> to see if the process is still running or not. But, not being able to find anything in particular. Any clue on this... (4 Replies)
Discussion started by: Haimanti
4 Replies

8. Shell Programming and Scripting

Copying specific files from remote m/c to specific folders

Hi All, I am trying to rsync some of the latest files from remote m/c to my local linux box. Folder structure in my remote m/c looks like this /pub/Nightly/Package/ROLL/WIN /pub/Nightly/Package/SOLL/sol /pub/Nightly/Package/SOLL/linux Each of the folder contains gzip files which on daily... (0 Replies)
Discussion started by: jhoomsharabi
0 Replies

9. Shell Programming and Scripting

check timestamp on specific files

I have a health check script homed in /u/ainet/scripts I need to check the time stamp on a file in /opt/config/log/ The file is called Backupdisk.out I want write the same info that you get when you do a ls -l into a file This is what I have been trying: cd /opt/config/log/ ls -l | awk... (2 Replies)
Discussion started by: grinds
2 Replies

10. Shell Programming and Scripting

How to check for specific process running through shell

Hi I want to check whether specific process is running or not through a shell script. ps -ef | grep will tell me this, i tried this way in shell cnt =`ps -ef| grep xyz | awk '{ END {print NR}}` if it return two rows, job is running else not. Is there any better way of doing this. (3 Replies)
Discussion started by: agp
3 Replies
Login or Register to Ask a Question