Are there any command that will check file ????


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Are there any command that will check file ????
# 1  
Old 12-30-2009
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?
# 2  
Old 12-30-2009
If you can do perl programming, then take a look at file::monitor: File::Monitor - search.cpan.org
# 3  
Old 12-30-2009
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:
https://www.unix.com/answers-frequent...n-crontab.html
# 4  
Old 12-30-2009
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
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
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX command to check if file name ends with .tar OR if the file is a tar file

Hello Team, Would you please help me with a UNIX command that would check if file is a tar file. if we dont have that , can you help me with UNIX command that would check if file ends with .tar Thanks in advance. (10 Replies)
Discussion started by: sanjaydubey2006
10 Replies

2. Shell Programming and Scripting

Command to check only Autosys running jobs with autorep like command

Hi, Is there any specific command to use to check only say Running jobs via autorep or similar command for Autosys? (0 Replies)
Discussion started by: sidnow
0 Replies

3. UNIX for Advanced & Expert Users

Command to check java file in UNIX

Guys, i need to check whether java file can be executed in my current unix system or not. Can anyone please help me to get the correct command to check this. My Unix system is HP-UX. Thanks, (1 Reply)
Discussion started by: AraR87
1 Replies

4. Shell Programming and Scripting

Script to check one command and if it fails moves to other command

Input is list of Server's, script is basically to remove old_rootvg, So it should check first command "alt_rootvg_op -X old_rootvg" if it passes move to next server and starts check and if it fails moves to other command "exportvg old_rootvg" for only that particular server. I came up with below,... (6 Replies)
Discussion started by: aix_admin_007
6 Replies

5. Shell Programming and Scripting

command to check existence of file name which has regex

Hi All. Pls help me with the command to check existence of files (I'll mention name of the file as regex) and proceed with my further processing if atleast one of them exists in detail, I've a dir /tmp/TURP, which may or may not have files named with "exter*.txt" I need to check and... (2 Replies)
Discussion started by: skpvalvekar
2 Replies

6. 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

7. Shell Programming and Scripting

How to check if a command returns nothing

Hi, I want to write a script that runs a command (at -l) and writes the output to a file. If the command (at -l) command returns no value (is empty/null) then write a message to the file in place of the command output. My problem is around trapping the empty returned command value and replacing... (2 Replies)
Discussion started by: Alvescot
2 Replies

8. Shell Programming and Scripting

one line command to check file existence and FTP it

Hi all, I need a batch script to Check for existence of file say i check for files with extension xml.done in C:\Myfile.(This folder contains .xml file and its corresponding .done files) If the .done file exists then it should FTP the corresponding .xml file to UNIX. Is this possible to do... (6 Replies)
Discussion started by: Codesearcher
6 Replies

9. Shell Programming and Scripting

How can I make the for command check to see if a file is empty before executing?

Here is the command in question for f in $(<uploads); do . I only want this to execute if uploads is not empty. If uploads is empty I want the script to quit, actually before the for command. If its not apparent uploads is a text file. Chris (3 Replies)
Discussion started by: chrchcol
3 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