Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Need an hook to the Solaris file system

Posted on 2006-04-13
5
Medium Priority
?
403 Views
Last Modified: 2013-12-21
Hi Friends

  I am looking for  some hook to the Solaris file system at the OS level which will generate a notification to my program whenever a file is created or deleted. The notification needs to contain the filename, filepath and the type of filechange (i.e. Creation/deletion)

Any suggestions ?

Regards
Manish

0
Comment
Question by:vikrant_kpr
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:CadburyKat
ID: 16446649
Hello,

You may need to get a little creative here.
-----------------SNIP---------------------------------
#!/bin/ksh

if [ -f /tmp/out.dat ]
then
   mv out.dat out.dat.old
fi

find /var/opt | sort > /tmp/out.dat

#This will report the differences

diff /tmp/out.dat /tmp/out.dat.old

#if you want to compare and contrast dates you will need to do something like this

if [ -f /tmp/ls.out.dat ]
then
   mv /tmp/ls.out.dat  /tmp/ls.out.dat.old
   for file in `cat /tmp/out.dat`
   do
      ls -al ${file} > /tmp/ls.out.dat
   done
fi

for file in `cat /tmp/out.dat`
do
   ls -al ${file} > /tmp/ls.out.dat
done
0
 
LVL 2

Expert Comment

by:CadburyKat
ID: 16446663
OOOPS.  Use this working script:


#!/bin/ksh

touch out.dat.old

if [ -f /tmp/out.dat ]
then
   mv out.dat out.dat.old
fi


#######################################
#EDIT the directory of interest here
#######################################
find /etc/patch | sort > /tmp/out.dat

#This will report the differences
echo "#######################################"
echo "These are the files that are different"
echo "#######################################"
diff /tmp/out.dat /tmp/out.dat.old

#
#
#
#if you want to compare and contrast dates you will need to do something like this

if [ ! -f /tmp/ls.out.dat.old ]
then
   touch /tmp/ls.out.dat.old
fi

if [ -f /tmp/ls.out.dat ]
then
   mv /tmp/ls.out.dat  /tmp/ls.out.dat.old
fi

for file in `cat /tmp/out.dat`
do
   if [ ! -d ${file} ]
   then
      false
   else
      ls -al ${file} >> /tmp/ls.out.dat
   fi
done


#This will report the differences
echo "#######################################"
echo "These are the files that are different"
echo "#######################################"
diff /tmp/ls.out.dat /tmp/ls.out.dat.old
0
 
LVL 7

Expert Comment

by:XoF
ID: 16446962
have a look at this thread:
http://www.experts-exchange.com/Operating_Systems/Linux/Q_21806194.html

famd for example should be available for Solaris, too AFAIK.

HTH,
-XoF-
0
 
LVL 10

Expert Comment

by:Nukfror
ID: 16456074
Blastwave has fam for Solaris:

http://www.blastwave.org/packages.php/fam

Haven't used it so can't say how well it works.
0
 
LVL 7

Accepted Solution

by:
XoF earned 1000 total points
ID: 16456234
as posted in the above mentioned thread:

#include <stdio.h>
#include <fam.h>
#include <unistd.h>

FAMConnection* fc;
FAMRequest* fr;
FAMEvent* fe;

int main(int argc,char* argv[]){
  char* dir=argv[1];
  fc = (FAMConnection*) malloc(sizeof(FAMConnection));
  fr = (FAMRequest*) malloc(sizeof(FAMRequest));
  FAMOpen(fc);
  if(fc){
    FAMMonitorDirectory(fc,dir,fr,NULL);
    if(fr){
      fe = (FAMEvent*) malloc(sizeof(FAMEvent));
      while(1){
        FAMNextEvent(fc,fe);
        switch(fe->code){
          case FAMDeleted:
            printf("File %s deleted\n",fe->filename);
            break;
          case FAMCreated:
            printf("File %s created\n",fe->filename);
            break;
        }
      }
      FAMCancelMonitor(fc,fr);
      free(fe);
    }
    FAMClose(fc);
  }
  free(fr);
  free(fc);
  return(FAMErrno);
}


Save this snippet as "dmon.c". Then do a "gcc -lfam -o dmon dmon.c".
Call the sample prog as "./dmon <directory>". (make sure, that famd is running before - no error handling implemented)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question