Sponsored Content
Full Discussion: script to monitor directory
Top Forums Shell Programming and Scripting script to monitor directory Post 302227947 by ddreggors on Friday 22nd of August 2008 09:58:52 AM
Old 08-22-2008
Nice work otheus, I have been playing with that and, here is a test script that you can change as you need.

Some points,

1. The file must exist so "touch" test1.txt first
2. You will need to open 2 terminals and open the file you are testing in vi/vim on one and run this in another.
3. Use sudo or run as root (lsof requires root on RedHat)


Code:
#!/bin/bash

# Assuming you will use fileschaned output to get new filename 
# and also assuming that you will want to test THIS process before
# trying to incorperate fileschanged into the process...
# I wrote this as a test of the lsof side of the code.


# Assuming you test from your (not root) home directory and use sudo
# change as needed

WHO=`who am i |awk '{print $1}'`
DIR="/home/$WHO"
FILE=".test1.txt.swp"
CTR=0

while true
do
        # Attempt to sanely exit after 3 runs
        if [ "$CTR" -eq 3 ]
        then
                killall vim
        fi

        # Do you file open/closed logic here
        if [ -f $DIR/$FILE ]
        then
                LSOF=`lsof $DIR/$FILE`
        else
                unset LSOF
        fi
        echo -n `date +%s`:
        if [ -n "$LSOF" ]
        then
                echo "$DIR/$FILE is OPEN";
        else
                echo "$DIR/$FILE is CLOSED";
                exit
        fi
        CTR=`expr $CTR + 1`
done

here is the output:

1219411794:/home/ddreggors/.test1.txt.swp is OPEN
1219411794:/home/ddreggors/.test1.txt.swp is OPEN
1219411794:/home/ddreggors/.test1.txt.swp is OPEN
1219411794:/home/ddreggors/.test1.txt.swp is CLOSED

Last edited by ddreggors; 08-22-2008 at 11:18 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Hep with script to monitor directory

Hello, I am a newbie who is attempting to write a script to monitor a directory for a set of 3 files that I am expecting to get ftp'd. Occasionally, we suspend operations for maintenance etc. but we still get the files so there can be more than 1 set. If there is more than 1 set, I would like... (2 Replies)
Discussion started by: cmf00186
2 Replies

2. Shell Programming and Scripting

script to monitor files in a directory and sending the alert

Hi All, We are having important config files in an directory which was accessable by all /auto/config/Testbed/>ls config1.intial config2.intial config3.inital often we find that some of the lines are missing in config files, we doubt if some one is removing. I would like to write... (0 Replies)
Discussion started by: shellscripter
0 Replies

3. Shell Programming and Scripting

Monitor capacity of directory

Good morning. I have been attempting to find a way to monitor the capacity of a directory so that when it reaches 80% or higher I can send an event. I was able to find a script that does this for the whole drive by I can not seem to figure out how to do this for just a single directory. ... (1 Reply)
Discussion started by: LRoberts
1 Replies

4. AIX

monitor directory events

I'm am looking for a cheap way to trigger a script when a new file is written in a specific directory. AIX 5.3. It is a production system, so no kernel patching (i.e. inotify). Filemon and audtiing are too expensive. Thanks in advance. (2 Replies)
Discussion started by: pbillast
2 Replies

5. UNIX for Dummies Questions & Answers

Monitor directory and email

Hello all, Can anyone please guide / help me in the following task.... I have a directory where some external users will upload pdf files. The filename of these pdf will be of a particular format (<id>-<first name>_<last name>_<some number>.pdf) I want to make a script such that it takes... (6 Replies)
Discussion started by: dhawalkv
6 Replies

6. Shell Programming and Scripting

Directory Monitor in KSh

Hi, I need to write a directory monitor, i.e. a korn shell script which would Report changes to the directory contents, like: added file1, deleted file2, updated file3 , created subdir (optional)... There is no specific file pattern. So far I have written a little script... (1 Reply)
Discussion started by: olegkon
1 Replies

7. Shell Programming and Scripting

Script to monitor directory size of specific users

Hi, i am new to shell scripts, i need to write a script that can monitor size of directory of specific users. Please help. Thanks, Nitin (2 Replies)
Discussion started by: nicksrulz
2 Replies

8. Shell Programming and Scripting

Shell script to monitor new file in a directory and mail the file content

Hi I am looking for a help in designing a bash script on linux which can do below:- 1) Look in a specific directory for any new files 2) Mail the content of the new file Appreciate any help Regards Neha (5 Replies)
Discussion started by: neha0785
5 Replies

9. Shell Programming and Scripting

awk to monitor size in directory

i'm trying to find the most efficient way to monitor specific files in different directories in one go. /var/log/ /var/app/ /var/db/ each one of these directories can have subdirectories which need to be looked into as well. I want to find any file in this directory that has the name... (7 Replies)
Discussion started by: SkySmart
7 Replies

10. Shell Programming and Scripting

Bash script monitor directory and subdirectories for new pdfs

I need bash script that monitor folders for new pdf files and create xml file for rss feed with newest files on the list. I have some script, but it reports errors. #!/bin/bash SYSDIR="/var/www/html/Intranet" HTTPLINK="http://TYPE.IP.ADDRESS.HERE/pdfs" FEEDTITLE="Najnoviji dokumenti na... (20 Replies)
Discussion started by: markus1981
20 Replies
APPLE_DUMP(1)							   Netatalk 2.2 						     APPLE_DUMP(1)

NAME
apple_dump - Dump AppleSingle/AppleDouble format file SYNOPSIS
apple_dump [-a] FILE | DIR apple_dump -f FILE apple_dump -d FILE apple_dump -h | -help | --help apple_dump -v | -version | --version DESCRIPTION
apple_dump dump AppleSingle/AppleDouble format file. OPTIONS
-a FILE|DIR This is default. Dump a AppleSingle/AppleDouble file for FILE or DIR automatically. Extrapolate FinderInfo type from absolute path. If FILE is not AppleSingle/AppleDouble format, look for .AppleDouble/FILE and ._FILE. If DIR, look for DIR/.AppleDouble/.Parent and ._DIR. -f FILE Dump FILE. Assume FinderInfo to be FileInfo. -d FILE Dump FILE. Assume FinderInfo to be DirInfo. -h, -help, --help Display the help and exit -v, -version, --version Show version and exit NOTE
There is no way to detect whether FinderInfo is FileInfo or DirInfo. By default, apple_dump examins whether file or directory, a parent directory is .AppleDouble, filename is ._*, filename is .Parent, and so on. If setting option -f or -d, assume FinderInfo and doesn't look for another file. SEE ALSO
ad(1) Netatalk 2.2 02 Sep 2011 APPLE_DUMP(1)
All times are GMT -4. The time now is 03:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy