sh script for file received confirmation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sh script for file received confirmation
# 1  
Old 06-07-2011
sh script for file received confirmation

I am new at scripting, (and this fourm- so hi guys!) and I was wondering is there something out there that I can use to do the following:

I receive a file on an FTP server
I would like a script to look at a specifc directory for a certain file
and when it arrives it will send an email confirmation.

the only caveat i see is that the same file sits there in the directory
until a new one overwrites it each day. so there will always be a file there.


I already have sendmail running so that is no issue


anything out there that I can modify?

please help!

Smilie

Thanks..
# 2  
Old 06-07-2011
In sh: Tweak F to your needs. A bit quick but it should work

Code:
#!/bin/sh

F='/path/to/that/certain/file'
MD5='/tmp/md5ofthatcertainfile'

[ "$(md5sum "$F")" = "$(cat "$MD5" 2>/dev/null)" ] || {
	md5sum "$F" > "$MD5"
	# Send your e-mail here
}

exit 0

Schedule it with cron (crontab -e typically)

Last edited by tukuyomi; 06-07-2011 at 05:55 PM..
This User Gave Thanks to tukuyomi For This Post:
# 3  
Old 06-07-2011
Crontab this script before time of earliest arrival:
Code:
#!/usr/bin/ksh
 
touch /tmp/fmind.mark
 
while [ 1 ]
do
  find your_file -newer /tmp/fmind.mark | read f
  if [ "$f" != "" ]
  then
   break
  fi
  sleep 120
done
 
ls -l $f | mailx -s "New $f" you@yours.com

This User Gave Thanks to DGPickett For This Post:
# 4  
Old 06-08-2011
MySQL Script to send email after file received form FTP

Thanks again to both of you!
I played with them both and this is what I can up with.
Seem to work when i run it as a cron every hour, if the file has been changed it will send the email.
Code:
#!/bin/sh
F='/home/test'
MD5='/tmp/md5ofthatcertainfile'
[ "$(md5sum "$F")" = "$(cat "$MD5" 2>/dev/null)" ] || {
        md5sum "$F" > "$MD5"
SUBJECT="test file"
EMAIL=myemail@email.com
EMAILMESSAGE="test file"
echo "test file received successfully"> $EMAILMESSAGE
echo "This is an automated message please do not reply" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
}
exit 0

would you guys have done anything differently?

I am new at this, so it may look a bit ugly.. haha

I had one other question

How can I incorporate in the email, the date,time stamp of the file?
that would be the last piece Smilie

again this is a big help.. thanks...

Last edited by Scott; 06-08-2011 at 03:07 PM.. Reason: Please use code tags
# 5  
Old 06-08-2011
One caveat is that the file might not be wholly received to set the modify time or change checksum or hash. Nice file transmitters have some way to signal a good transfer, like an ack file or name change. At least, before using the file, use fuser to ensure it is not still being written.
This User Gave Thanks to DGPickett For This Post:
# 6  
Old 06-08-2011
So could I use fuser to tell me if the file is still being transmitted vs completed?
# 7  
Old 06-08-2011
If you don't mind a bit of delay, there's a much simpler way: Check if the file's been modified in the last 10 minutes. This won't tell you if the connection broke and left an incomplete file, but neither will fuser.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find directory is getting files in every 10 mins, if not then when last time file received

Dears, I am looking for a script which will work as a watch directory. I ha directory which keep getting files in every 10 mins and some time delay. I want to monitor if the directory getting the files in every 10 mins if not captured the last received file time and calculate the delay. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

Invoke a shell script in case mail with a specific subject is received

Hello fellow forum members, I have a script which returns a date (I can design the script to return the value in email), How can I design the script in AIX to invoke another shell script which performs some set of actions. Procmail doesnt work in AIX. (4 Replies)
Discussion started by: ektubbe
4 Replies

3. Shell Programming and Scripting

How to check email with attachment received or not from UNIX shell script?

Hello Guys, Here is the requirement!! I want to check the mail with attachment received or not through unix scripting. And send an notification email when mail with attachment already received. Any thoughts on this is much appreciated!! Regards, Harry (0 Replies)
Discussion started by: dharry2017
0 Replies

4. Shell Programming and Scripting

Confirmation while deleting a file

Hi All, While am deleting a file in unix by using the command rm it's deleting the file directly IT's have to ask the user while deleting like do you want to delete filename y or N ? Kindly help on this. Thanks Thelak (2 Replies)
Discussion started by: thelakbe
2 Replies

5. Programming

unexpected values received when writing and reading from file

In the code below i try to write and read from a file, but i get unexpected results, like after writing i cannot open the file, and when reading the file the value entered earlier is not shown bool creat_fragments(int nFragment) { int fd, rand_value; char frag_path, buf; for(int... (8 Replies)
Discussion started by: saman_glorious
8 Replies

6. Linux

Run PHP script when new email received

I have been looking around for a solution to this, i have been developing for a wile though am very new to CGI, PHP and a lot of the web based tech. I have a web site hosted with a cPanel web host. I am looking to have a script(prefer PHP) to run everytime i get a new email to help@xxx.com.... (16 Replies)
Discussion started by: iKris
16 Replies

7. Shell Programming and Scripting

twice confirmation in the script

from one script invoke another script will need to do double confirmation like: 'y' and 'y' exp: echo 'y' | /a/b/c.sh only input 1 'y' in the c.sh, but the c.sh required 2 'y' (twice confirmation) is there anyway get resolve this issue? please help (2 Replies)
Discussion started by: kinx
2 Replies

8. Shell Programming and Scripting

Pass all received args to a (wrapped) child script

I'm writing a wrapper script (in bash) that wraps another (bash) script. When calling the wrapped script, I need to pass all the received arguments/options to it. Is there a built in variable that holds all the options? I wrote a little while loop (see below) which works. But I wanted to know if... (1 Reply)
Discussion started by: Dilbert
1 Replies

9. Shell Programming and Scripting

How do I write a ksh script that will check if all ftp files are received?

I am trying to code a ksh script that will check to see if all 26 incoming ftp files have been received before proceeding to the next function, which is to rename each file. Here is the pseudo-code of what I am trying to do: <<STEP_1>> IF all ALS files have been transmitted then... (2 Replies)
Discussion started by: doug145
2 Replies

10. Shell Programming and Scripting

Checking the time of last file received?

Hi, Is there a way of looking at the last file received and checking whether it is more than 24 hours old? E.g. /Archive/Files/h/h0012345.dat I need to look in a directory, get the date of the processed file and make sure it wasn't more than a day ago. If it is more than 1 day ago I need... (9 Replies)
Discussion started by: rebootman
9 Replies
Login or Register to Ask a Question