Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
google site



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-30-2009
Registered User
 

Join Date: Sep 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Are there any command that will check file ????

Hi all,

i will write a script. Script will sense certain directory and if a file is created it will send me an email.

i know how mail is sent. But i dont know which command that check directory for file is created or not continuously.

Thanx for your helping.

---------- Post updated at 04:19 AM ---------- Previous update was at 04:17 AM ----------

shortly, when someone created or send a file to certain directory my script have to send me a email.

---------- Post updated at 04:19 AM ---------- Previous update was at 04:19 AM ----------

how can i success this?
Sponsored Links
  #2  
Old 12-30-2009
thegeek thegeek is offline Forum Advisor  
Registered User
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 870
Thanks: 2
Thanked 10 Times in 8 Posts
If you can do perl programming, then take a look at file::monitor: File::Monitor - search.cpan.org
  #3  
Old 12-30-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 

Join Date: Sep 2007
Location: Germany
Posts: 3,238
Thanks: 7
Thanked 47 Times in 45 Posts
You can check with test if a file exists; example:


Code:
[[ -e somefile ]] && echo ok

Can also include it into a if/then/fi of course, etc.

To have some repeating checks you might want to add it as a cron job.
For cron you might read up here:
cron and crontab
  #4  
Old 12-30-2009
Registered User
 

Join Date: Sep 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
i know these ways, i curious are there any command?
Thanx.
i know two way:
1-i write "[[ -e somefile ]] && echo ok" sentence in a script and call it via cron per 1 minute
2- i write "[[ -e somefile ]] && echo ok" sentence in a scirpt and call it in while loop.
and there is "sleep 60" command in loop.

i had curioused are there any command(will run backgroun of OS) sense directory for file.

thanx
  #5  
Old 12-30-2009
thegeek thegeek is offline Forum Advisor  
Registered User
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 870
Thanks: 2
Thanked 10 Times in 8 Posts
i dont believe such a process is there in any OS.. why at all it is required, then it will become a resource intensive in a heavily used file servers.
  #6  
Old 12-30-2009
Registered User
 

Join Date: Mar 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
2 ways I firgured out to meet your needs:

1) check the stimestamp of the directory ( Because once a file created, the directory's modification time is necessarily updated ). Save the the last timestamp and compare the most recent one to it to see if the timestamp has been changed

2) Use checksum (cksum command)... briefly, compare old checksum of the contents of the directory with the new checksum if the there is a change. If yes, new file has been created in that dir.
The detailed code may look like this:

Quote:
old_cksum=`ls -a urdir|cksum`
while :;do
sleep 60 # check every minute
new_cksum=`ls -a urdir|cksum`
[ $old_cksum = $new_cksum ] || mailx ....
old_cksum=$new_cksum
done
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
one line command to check file existence and FTP it Codesearcher Shell Programming and Scripting 6 05-12-2009 08:06 PM
How can I make the for command check to see if a file is empty before executing? chrchcol Shell Programming and Scripting 3 07-29-2006 03:14 AM
Script to check for a file, check for 2hrs. then quit mmarsh UNIX for Dummies Questions & Answers 2 09-16-2005 02:46 PM
command for check CPU abcde UNIX for Dummies Questions & Answers 2 05-09-2005 11:47 AM
command to check the bit raguramtgr UNIX for Dummies Questions & Answers 2 07-12-2004 10:38 AM



All times are GMT -4. The time now is 07:47 AM.