views:

944

answers:

2

1st of all: I'm not programmer, neither Linux guru, just have to work with Linux, Oracle, shell scripts.

My current task is to monitor a table in Oracle (tool: sqlplus), and if it contains a certain row, then watch a linux directory for a growing tmp file, and log its attributes (e.g. ls -l), in every 5 second.

The most important part is: this tmp file will be deleted if the above record is deleted from the oracle table, and I need the last contents of this tmp file.

I can't control the Oracle data, just got query rights.

The available tools are: bash, awk, sed, some old version of perl, ruby (not 1.9*), and python (2.5). I don't have install rights, so most of the outside libraries are not accessible. I know I can run some libraries from my $HOME, but I don't have internet connection on that machine: so can't download any library.

Inotify is not available (older kernel).

Any idea where to start/how to do it? Thanks in advance.

+3  A: 

How about creating a hard link in another directory, then, when the file "disappears" in the original location, the hard link will still have access to the content.

Sunny
Good idea, (that's why I had upvoted), but most probably I don't have write access on the tmp file's filesystem. I can check it at work only...
Zsolt Botykai
+1  A: 

This is ugly and naive... but...

#!/bin/bash

WASTHERE=0
MONITORING=/tmp/whatever.dat
LASTBACKUP=/tmp/mybackup.dat
LOGFILE=/tmp/mylog.log

# Just create an empty file to start with
touch "$LASTBACKUP"

while [ 1 ];
do
        if [[ ! -e "$MONITORING" ]]; then
                if [[ $WASTHERE -ne 0 ]]; then
                        echo "File is gone!  Do something with $LASTBACKUP";
                        WASTHERE=0
                fi
        else
                WASTHERE=1
                ls -l "$MONITORING" >> $LOGFILE
                cp "$MONITORING" "$LASTBACKUP"
        fi

        sleep 5
done

The unfortunate part about this is that if anything happens to the file being 'monitored' while the script is sleeping (content is written to it, for example) and the file is then deleted before the script wakes up, the newly written content will not be in the 'backup.'

Sean Bright
Looks like I need something like this... Will give a try when I get in tomorrow.
Zsolt Botykai
Based on your idea, I had write my version, thanks for your help.
Zsolt Botykai