Check File availability


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check File availability
# 1  
Old 10-22-2011
Check File availability

Hi,
I have a task to write a script , which will run everyday to check whether my system has received 2 files from source system. It should mail me ( using mailx preferably ) if the files has not arrived from the source.

The scenario is everyday I get 2 files from source system., sometime they miss to send those files ., ( files are in server) so i need to manually go and check in a path to check for its availability so I want to automate it by sending mail to me if files were missing !! Plz help..
# 2  
Old 10-23-2011
Code:
chkfilez () {
for i in $1/$2; do
test -f $i && printf  "$i found \n" || printf "$i not found \n"
done
}

chkfilez	"$HOME"	"*.txt"

Will look for "*.txt" files in $HOME directory, supports regex match multiple or single file.
I'm sure you'll figure how to mail those Smilie
This User Gave Thanks to Peasant For This Post:
# 3  
Old 10-23-2011
Thanks a lot !!! It worked perfectly Smilie

---------- Post updated 10-24-11 at 12:17 AM ---------- Previous update was 10-23-11 at 11:13 PM ----------

Hi Peasant,
I got a problem with the code., its sending mails even if the files have come., this is the script i have used
Code:
SOURCE_DIR=$Path

export FILE1=$SOURCE_DIR/brs*.dat
export FILE2=$SOURCE_DIR/brt*.dat
export  MSG=" files did not arrive ., please check with Source system"
chkfile () 
{
for i in $FILE1/$FILE2; do
test -f $i && j=0 || j=1  
done
if [ $j -eq 1 ];then
echo $MSG | mailx -s " files missing " -r "Report" mailid
fi
}
 
  chkfile "SOURCE_DIR""br*.dat"

I dont know where i went wrong., i get mails but the issue is even if the file is present i m getting it Smilie

Last edited by Franklin52; 10-24-2011 at 03:49 AM.. Reason: Please use code tags, thank you
# 4  
Old 10-24-2011
Invoke function chkfilez twice for each regex file type.
Code:
chkfilez "$SOURCE_DIR" "brs*.dat"
chkfilez "$SOURCE_DIR" "brt*.dat"

Leave the function to take parameters, don't put them inside.
Code:
for i in $1/$2..

where $1 is $SOURCE_DIR passed to chkfilez as first parameter, and one-type file regex match as $2 (so $2 in first case is brs*.dat, in second case brt*.dat).

If you want more advanced code, you will have to dive into arrays and case, this was just an example.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

High availability

hi guys I posted problem last time I didn't find answer to my issue. my problem is as below: I have two servers which work as an actif/standby in high availability system. but when i use command HASTAT -a i have the following message: couldn' find actif node. the servers are sun... (1 Reply)
Discussion started by: zineb06
1 Replies

2. Shell Programming and Scripting

Check file availability and place flag file

I have to check a directory on Linux (via shell Script which I am trying to build) for about 20 different source files with file patterns and if the files are made available in the directory, I should place flag files for which my other ETL jobs are waiting on to kick off. If the source files are... (6 Replies)
Discussion started by: dhruuv369
6 Replies

3. UNIX for Dummies Questions & Answers

iscsi high availability

Hi, I want to set up a iscsi high availability with sheepdog distributed storage. Here is my system set up. Four nodes with sheepdog distributed storage and i am sharing this storage through iscsi using two nodes as well as using a virtual ip set up using ucarp.Two nodes using same iqn. And... (0 Replies)
Discussion started by: jobycxa
0 Replies

4. UNIX for Dummies Questions & Answers

For loop to check the files availability

Hi, I need a help with my script. Below is my script. What I am doing here is finding the date of the file which I need to process and then finding the list of file names. Based on the list of file names, check has to be done to see if all the files are there and log the details to a error... (3 Replies)
Discussion started by: Vijay81
3 Replies

5. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

6. Shell Programming and Scripting

how to check availability of data of one file in other

hi all i have two files in unix 1.table.name 2.all.tables i need to check the availability of all data of table.name in all.tables.both the table contains n number of data.i need a script which will check one by one whether the data exist in table.name or not.I want this in SH. (1 Reply)
Discussion started by: alisha
1 Replies

7. Solaris

Check Database availability?

Hi All, My script gets aborted as it is connecting as a remote database through a DB link on every 3rd sunday.As the remote DB is down for more than 6 hours. Can TNSPING DBNAME inside my script ensure the database is up??? Then how can i check the database is up or down ? ... (2 Replies)
Discussion started by: megh
2 Replies

8. Solaris

Printer availability

Hi, Im new in shell programming. I need to know the availability for specific printers. We send requests from solaris to printers located at an NT server. My idea is creating a shell that will monitor availbaility and send an email when something is wrong. I have a file with printers and its... (2 Replies)
Discussion started by: agsarm1971
2 Replies

9. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies

10. Shell Programming and Scripting

case statement based on file availability

I need to make a select menu that gives options dynamically based on whether certain files are available. For instance: PS3="Open which readme? " select readme in This That do case "$readme" in This) open -a /Applications/TextEdit.app This.txt;; That) open -a... (6 Replies)
Discussion started by: Loriel
6 Replies
Login or Register to Ask a Question