Basic Script to check for a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Basic Script to check for a file
# 1  
Old 01-06-2010
Basic Script to check for a file

Hello,

Little new to unix scripting. I need to create a script that will do the following.

Check in a directory for a file that will be present between 19:00 and 23:00. If the file is present a e-mail then needs to be sent to myself confirming. I did write something basic...as below...

if [[ -d filename]]; then
mailx -s "File Present" xxx@xxx.com

However as I am new to this I have no idea to get the script to check only for a file for that days time stamp. As it stands the script would confirm the presence of the file even if was yesterdays.

On a side how do I get the script to shell out once completed?

Thanks
# 2  
Old 01-06-2010
Quote:
Originally Posted by Thundercat1
Hello,

Little new to unix scripting. I need to create a script that will do the following.

Check in a directory for a file that will be present between 19:00 and 23:00. If the file is present a e-mail then needs to be sent to myself confirming. I did write something basic...as below...

if [[ -d filename]]; then
mailx -s "File Present" xxx@xxx.com

However as I am new to this I have no idea to get the script to check only for a file for that days time stamp. As it stands the script would confirm the presence of the file even if was yesterdays.

On a side how do I get the script to shell out once completed?

Thanks
How about this.
Code:
find dir -newerat "19:00" -print0 | xargs -0 mailx -s "File Present" xxx@xxx.com

If you want by modification then use -newermt instead of -newerat in the options.
Regards.
Gaurav.
# 3  
Old 01-07-2010
Hi Thanks for the reply. However I am still having issues. I guess I need to check if a file has been recieved for today. The file will always have the same name however may have a different extention such as filename.tmp or filename.now. I came up with the following
Code:
RUNDATE=$(date + %b%e)
Filepmtdate=$(ls -l filename.* | awk '{print $6,$7}')

if (Filepmtdate = RUNDATE) ; then
  mailx -s "File has been Recived" xxx@xxx.com
else
  mailx -s "File has not been Recieved" xxx@xxx.com
fi

and yet this does not work. In addition I have no idea how to get the script to finish once I have initiated it. I have to ctrl D it to get back to the command line

Last edited by Scott; 01-07-2010 at 08:26 PM.. Reason: Added code tags, formatted code.
# 4  
Old 01-08-2010
Hi
maybe $(date + %b%e) is $(date +%b%e)

regard
jiajin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script fro file check and load the trail file

Hi, Im going to use shell script for load the data into DB. First i need to read the trail file(csv file has two columns with comma separated ) like file name trail1024(last 4 digitsMMDD). In this trail file 27 entries will have like below,I need to read first csv file name and get the 4... (1 Reply)
Discussion started by: krajasekhar.v
1 Replies

2. Shell Programming and Scripting

Shell script to read file and check file type

Hi, I have a file with few values in it. I need script help to read file line by line and check: 1/if it's a file (with extension eg .java .css .jar etc ) or 2/if it's a file without extension and treat it as a directory and then check if the directory exists in working copy else create one... (6 Replies)
Discussion started by: iaav
6 Replies

3. Shell Programming and Scripting

basic server check script - help

Hello Fellow bash enthusiasts... I am stuck on this local script and could use some fresh eyes on this code. #!/bin/bash MAIL_ME="jj@uberdork.com" MAIL_SUBJECT="Norveld_Server_needs_attention" SERVER_DATE=$(TZ=PST8PDT date) echo $(ServerTZ=PST8PDT date) - Web Server Check = $(curl -Is... (7 Replies)
Discussion started by: Habitual
7 Replies

4. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

5. Shell Programming and Scripting

Script check for file, alert if not there, and continue checking until file arrives

All, Is there a way to keep checking for a file over and over again in the same script for an interval of time? Ie If { mail -user continue checking until file arrives file arrives tasks exit I don't want the script to run each time and email the user each time a file... (4 Replies)
Discussion started by: markdjones82
4 Replies

6. AIX

Basic Filesystem / Physical Volume / Logical Volume Check

Hi! Can anyone help me on how I can do a basic check on the Unix filesystems / physical volumes and logical volumes? What items should I check, like where do I look at in smit? Or are there commands that I should execute? I need to do this as I was informed by IBM that there seems to be... (1 Reply)
Discussion started by: chipahoys
1 Replies

7. Shell Programming and Scripting

Check File Exists and compare to previous day file script

We have data files that are ftp'd every morning to a SUN server. The file names are exactly the same except for that each has the date included in its name. I have to write script to do 2 things: STEP 1) Verify that the file arrived in morning. STEP 2) Compare the file size of the current... (3 Replies)
Discussion started by: rbknisely
3 Replies

8. Shell Programming and Scripting

Have a shell script check for a file to exist before processing another file

I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still... (3 Replies)
Discussion started by: heprox
3 Replies

9. Shell Programming and Scripting

Help with a very basic network check script

i figured it out thanks though! (0 Replies)
Discussion started by: anon0mus
0 Replies

10. 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
Login or Register to Ask a Question