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
# 8  
Old 10-10-2008
Or even faster, if wc is printing the result right without any blanks in front of it:

Code:
NUM_NOW=`ls -1 /somedir/*xml| wc -l'`

You save another 0.001 second! Smilie Smilie
# 9  
Old 10-10-2008
Hi,

I am not sure about this terminology. I am new to UNIX.

I will explain what i am trying to do.

1) I want to keep track of all files which are getting created or coming from different server in a particular directory.
2) I want to store attributes of all files in different file.
e.g.

Suppose following files came to unix directory:

-rw-rw---- 1 rasadm unixadmin 12 Oct 06 08:19 file0.dat
-rw-rw---- 1 rasadm unixadmin 697 Oct 06 10:11 file1.dat
-rw-rw---- 1 rasadm unixadmin 505 Oct 06 10:11 file2.dat

Now,
When file0.dat is coming at 08:19 AM --
system should automatically detect the presence of new file and should add attributes of it ( Like timestamp, size ) to new file say filelog.dat.

When file1.dat and file2.dat are coming at 10:11 AM --
system should automatically detect the presence of new files and should add attributes of it ( Like timestamp, size ) to filelog.dat.

Please reply.
Its an urgent issue.

Thanks.
# 10  
Old 10-10-2008
Smilie Thanks Zaxxon ...

I will try to do it..
# 11  
Old 10-10-2008
Like this?

Code:
MY_LOG="/somelogdir/my.log"
IN_DIR="/somedir"
BEFORE="/tmp/before_snap325.tmp"
NOW="/tmp/after_snap723.tmp"

ls -1 | grep ^- > ${NOW}

grep -vf ${BEFORE} ${NOW} >> ${MY_LOG}

mv ${NOW} ${BEFORE}

exit 0

# 12  
Old 10-10-2008
Maybe we should add the date/time to the log:
Quote:
Originally Posted by zaxxon
Code:
....
ls -1 | grep ^- > ${NOW}
date >> ${MY_LOG}
grep -vf ${BEFORE} ${NOW} >> ${MY_LOG}
..

# 13  
Old 10-10-2008
Yep, can't hurt to keep track.
# 14  
Old 10-10-2008
file_list=./file_list

# File_list contains a file name of latest file processed when script ran the last time.

last_file=`cat $file_list`

find <directory where new files arrive> -newer $last_file

# Above command will give you list of all the new files arrived after $last_file


So, assume new files come in /etc then you will do the following:

last_file=`cat $file_list`
for a in `find /etc -newer $last_file`
do
ls -l $a >> logfile # Use cut or awk to just output selected attributes
done
echo $a > $file_list

Hope above will help.

Kind Regards
Ahmerin
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