Unix script to detect new file entry in directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix script to detect new file entry in directory
# 1  
Old 10-10-2008
Question Unix script to detect new file entry in directory

Hi All,

I want to detect each new file coming / getting created in unix directory.

When every new file came to directory, i have to get its details like its size , date and time stamp and store it into another file.

Could any one please tell me , how i can achieve that?

Thanks.
# 2  
Old 10-10-2008
man ls
Code:
ls -ltr | tail -1

# 3  
Old 10-10-2008
Hi,

I think this command will only give me the last file came to directory.

But, consider scenario when at same time more than 1 file came to directory. This command will not consider other files .

Further can i write this command in script and execute that script continuously ?

Do anybody has script wrtten for it ?

Thanks a lot for replying.
# 4  
Old 10-10-2008
Hi,

Or may be i can put my question as :

" One script should run everytime when new file comes to directory".

is this possible in UNIX ?

Please reply.

Thanks.
# 5  
Old 10-10-2008
Did you mean file system directory listeners ?
# 6  
Old 10-10-2008
You have either the choice that a script/program is running all the time and scanning that dir to inform you or maybe a cronjob running "only" every minute and checking let's say with something like:
Code:
TMP_FILE="/tmp/last_num_of_files.tmp"
NUM_BEFORE=`cat ${TMP_FILE}`
NUM_NOW=`ls -1 /somedir/*xml| wc -l | awk '{print $1}'`

if (( ${NUM_NOW} > ${NUM_BEFORE} )); then
     echo "Hey, it changed!"| mail -s "New files arrived" me@server.org"
fi

echo ${NUM_NOW} > ${TMP_FILE}

exit 0

# 7  
Old 10-10-2008
Quote:
NUM_NOW=`ls -1 /somedir/*xml| wc -l | awk '{print $1}'`
small change on top of it

Code:
NUM_NOW=`ls -1  | awk '{ cnt++ }END { print cnt }'`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to detect specific string in a log file and count it

Hello, can someone guide me on this? I don't know what is the best approach, (awk script, shell script) I am using RedHat Linux version 6.5. There is a third party application deployed on that server. This app by default generates 5 log files and each file is 20MB. These log rollover... (5 Replies)
Discussion started by: ktisbest
5 Replies

2. How to Post in the The UNIX and Linux Forums

Help me, write a bash script to delete parent entry with all their child entry in LDAP UNIX server

Hi All, Please help me and guide me to write a bash/shell script on Linux box to delete parent entry with all their child entries. example: Parent is : ---------- dn: email=yogesh.kumar@wipro.com, o=wipro, o=in child is: ---------- dn: cn: yogesh kumar, email=yogesh.kumar@wipro.com,... (1 Reply)
Discussion started by: Chand
1 Replies

3. Shell Programming and Scripting

Shell script to find if any new entry in directory

I require a shell script to find if any new entry of dump files present in a particular directory and to send an email if any new entry exists.I had a crontab to run the script for every 5 min. Below are the file names.dump.20150327.152407.12058630.0002.phd.gz... (9 Replies)
Discussion started by: bhas85
9 Replies

4. Shell Programming and Scripting

Script to detect dynamic ip change and update to config file

Hi All, I am newbie here and request your assistance. I have a service running on public ip, but since I have a dynamic IP it keeps on changing and every time I need to manually get the new ip and add to the config file and restart the service. This has become bit time consuming. Hence, I... (4 Replies)
Discussion started by: Shaan_Shaan
4 Replies

5. Shell Programming and Scripting

How to add each entry in an unix file?

Hi, I've a data file having entries like this- $ cat BDWL.out 19571 349484 18963 349568 20180 351389 20372 350253 Now I want to add each entry and produce the final sum =1479780 as output. How can I do that using unix shell scripting?? using loop or sed/awk ?? Thanks, Naresh (5 Replies)
Discussion started by: NARESH1302
5 Replies

6. Shell Programming and Scripting

script to detect a file from inserted usb and puts into a Variable

There is a same named log file that I have on my 2 different android phones. When I plug it into my computer, it appears in the media folder, For example the first android phone: /media/F6BA-0AF5/folder/A.log I want to put that into a variable to be manipulated.... (3 Replies)
Discussion started by: tobenguyen
3 Replies

7. UNIX for Dummies Questions & Answers

Not able to delete this file/directory/entry

Hello UNIX gurus, I noticed this file or whatever in one of our directories, and somehow I am not able to proceed with my work, without deleting this one. .insert--- 1 siebload intrface 0 Feb 22 01:25 Testfile I am confused, as it doesnt appear to be a file, and on doing any... (2 Replies)
Discussion started by: ppathak1234
2 Replies

8. Shell Programming and Scripting

AWK script to detect webpages from file

Hi guys I'm very new to unix and I have to create an awk script that detects webpage addresses from a file/webpage and outputs how many times each webpage was detected.e.g. if my file was: www.google.com www.facebook.com www.google.com the output should be: www.google.com x2... (2 Replies)
Discussion started by: ROFL
2 Replies

9. Shell Programming and Scripting

AWK script to detect webpages from file

Hi guys I'm very new to unix and I have to create an awk script that detects webpage addresses from a file/webpage and outputs how many times each webpage was detected.e.g. if my file was: (Note: The symbol " was added to stop them being created into links) "www.google.com"... (1 Reply)
Discussion started by: ROFL
1 Replies

10. Shell Programming and Scripting

FTP script for sending a file from one unix directory to another unix server director

Hi, My local server is :/usr/abcd/ Remote server is :/Usr/host/test/ I want to send files from local unix directory(All files starting with O_999) to remote host unix directory. Can any body give me the Unix Shell script to do this. One more doubt: Shall we need to change the file... (1 Reply)
Discussion started by: raja_1234
1 Replies
Login or Register to Ask a Question