File Accessed Alarm ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Accessed Alarm ??
# 1  
Old 09-17-2007
Error File Accessed Alarm ??

Hey,

I want to ask a simple Question....

How would I be able to come to know that files/directoires in a Parent directory has been accessed (means contents of the file has been just viewed) by the user(s) in a group ? and mail the name(s) of those files/directories which has been accessed recently in past 1 or 2 minutes with the name of the user who viewed the files/direcotries.

How will I write script for this ??

Please answer this QUESTION asap as I am after this problem for past 15 days and I did't get any perfect answer.

Please Help !!Smilie
Thanks !!
# 2  
Old 09-18-2007
Try This one

Hey Varun,
Hope you guys are doing Gr8 !! Smilie
Once again I dun have any *NIX box with me. So why Just giving one logic by which you will get your answer.
-------------------------------------------------------------
#!/bin/bash

## List all the files which one accessed since last 1 min #####
for file_dir in `find <parent-dir> -atime -1`

do

### Find out the PID for that files which one been accessed
pid=`fuser -f $file_dir`

### Find out the owner/user name for that Process
### Replace the $access_user_filed with the filed no from the ps -ef
### command
user=`ps -ef | grep $pid | awk { print $access_user_filed }`
echo " $file_dir access by the $user " >> File_Access_List "
mail -s " File Access List " user@yourdomain.com < File_Access_List
done
# 3  
Old 09-18-2007
CPU & Memory

Quote:
Originally Posted by SanjayLinux
Hey Varun,
Hope you guys are doing Gr8 !! Smilie
Once again I dun have any *NIX box with me. So why Just giving one logic by which you will get your answer.
-------------------------------------------------------------
#!/bin/bash

## List all the files which one accessed since last 1 min #####
for file_dir in `find <parent-dir> -atime -1`

do

### Find out the PID for that files which one been accessed
pid=`fuser -f $file_dir`

### Find out the owner/user name for that Process
### Replace the $access_user_filed with the filed no from the ps -ef
### command
user=`ps -ef | grep $pid | awk { print $access_user_filed }`
echo " $file_dir access by the $user " >> File_Access_List "
mail -s " File Access List " user@yourdomain.com < File_Access_List
done
Hey,

Thanks buddy...I'll come back to you with the results of your post.
It looks fine !! Smilie
# 4  
Old 09-18-2007
Quote:
Originally Posted by SanjayLinux
Hey Varun,
Hope you guys are doing Gr8 !! Smilie
Once again I dun have any *NIX box with me. So why Just giving one logic by which you will get your answer.
-------------------------------------------------------------
#!/bin/bash

## List all the files which one accessed since last 1 min #####
for file_dir in `find <parent-dir> -atime -1`

do

### Find out the PID for that files which one been accessed
pid=`fuser -f $file_dir`

### Find out the owner/user name for that Process
### Replace the $access_user_filed with the filed no from the ps -ef
### command
user=`ps -ef | grep $pid | awk { print $access_user_filed }`
echo " $file_dir access by the $user " >> File_Access_List "
mail -s " File Access List " user@yourdomain.com < File_Access_List
done
Hey,
please clarify my doubt..
What is $access_user_filed , used in the following command ?user=`ps -ef | grep $pid | awk { print $access_user_filed }`

In ps -ef we have following columns..
UID PID PPID C STIME TTY TIME CMD
Are you talking about UID or anything else ??
# 5  
Old 09-18-2007
Sorry It is my typo.

$access_user_filed is actuly the UID(user id ) Filed no from the out put of ps -ef command

~~Thanks~~~
# 6  
Old 09-27-2007
Error

Quote:
Originally Posted by SanjayLinux
Sorry It is my typo.

$access_user_filed is actuly the UID(user id ) Filed no from the out put of ps -ef command

~~Thanks~~~
NO probs, I got that !!
Thnks !!Smilie
# 7  
Old 09-27-2007
Question

Quote:
Originally Posted by varungupta
Hey,
please clarify my doubt..
What is $access_user_filed , used in the following command ?user=`ps -ef | grep $pid | awk { print $access_user_filed }`

In ps -ef we have following columns..
UID PID PPID C STIME TTY TIME CMD
Are you talking about UID or anything else ??
Hey ,

When I run the script it gives me following error :

AccessLogMonitor_script[11]: 0403-057 Syntax error at line 23 : `"' is not matched.
And my script is, as per your suggestions :
---------------------------------------------------------------------
#SCRIPT TO CHECK WHO HAS ACCESSED THE LOG/FILE IN PAST 'N' MINUTES, AND MAIL ACCORDINGLY.

MYPATH="/clocal/mqbrkrs/user/mqsiadm/sanjay/"
MAIL_RECIPIENTS="abc@xyz.com"
Subject="File accessed in last few minutes are ::"
>tempmail.txt
>tempfind.txt

## List all the files which one accessed since last 1 min #####

for file_dir in `find $MYPATH -amin -1`
do
### Find out the PID for that files which one been accessed
pid = `fuser -f $file_dir`

### Find out the owner/user name for that Process
### Replace the $access_user_filed with the filed no from the ps -ef
### command
user = `ps -ef | grep $pid | awk { print $1 }`
echo " $file_dir access by the $user " >> tempmail.txt "
done

cat tempmail.txt | mailx -s "$Subject" "$MAIL_RECIPIENTS"
---------------------------------------------------------------------
Smilie
Suggest me !!
Thanks !!

Last edited by varungupta; 09-27-2007 at 08:05 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find file that are accessed less than 10 minutes in a directory

Hi All,, I need to find the latest files that are accessed less than 10mins in a particular directory & send those files in an attachment. I could use the below simple one. But if the directory was not updated any recently i could mail the old file again, i need to eliminate that.. What shld... (8 Replies)
Discussion started by: Jeevitha
8 Replies

2. UNIX for Dummies Questions & Answers

File shows in ls but cannot be accessed

I can do an ls -l CD* and see the following CDTEST userA RW RW R and I an logged on as userA. But if I do an ls -l the file does not appear. If I do a vi CDTEST it tries to create a new file named CDTEST. If I do a mv or rm I get the message no file of name CDTEST found. Any idea what is going on.... (3 Replies)
Discussion started by: LeeT
3 Replies

3. UNIX for Advanced & Expert Users

How to find out last 5 users who have accessed a file?

Hi All, is there any command or script to find out last five users who have accessed a file thanks jcpratap (1 Reply)
Discussion started by: Jcpratap
1 Replies

4. Shell Programming and Scripting

check if file is being accessed by any application

Hello, is there maybe a way to check if a specific file is being accessed at the moment? Example: You will start copying a 10 GB file from A to B, how could I code it so my script actually knows when file B is finished copying? (1 Reply)
Discussion started by: TehOne
1 Replies

5. AIX

File Accessed Alarm ??

Hey, I want to ask a simple Question.... How would I be able to come to know that files/directoires in a Parent directory has been accessed (means contents of the file has been just viewed) by the user(s) in a group ? and mail the name(s) of those files/directories which has been accessed... (1 Reply)
Discussion started by: varungupta
1 Replies

6. Shell Programming and Scripting

Can we get the list of users who accessed a file

Hi all, I will thankful if anybody helps me in finding out the users who accessed any of our files. Thanks in advance Chanakya (2 Replies)
Discussion started by: Chanakya.m
2 Replies

7. Shell Programming and Scripting

how to know which login file is being accessed

when unix is logged in it access some login file depending on the shell like .cshrc , .login , .vimrc , .bashrc how can we know which is being access in a perticular unix flavor. (1 Reply)
Discussion started by: useless79
1 Replies

8. UNIX for Dummies Questions & Answers

list file which is accessed yesterday

how can I use 'ls' to list file which is accessed yesterday? Thx :confused: (2 Replies)
Discussion started by: aaron_fong
2 Replies

9. Shell Programming and Scripting

Counting Number of times a File is accessed

Hi, I need to count the number of times a script is accessed from within the script. Is it possible ? Example: I have a script called lo.sh and i execute the script for the first time, then the counter variable declared inside the lo.sh should increment by 1. For every execution the... (1 Reply)
Discussion started by: pathanjalireddy
1 Replies

10. UNIX for Dummies Questions & Answers

How to check if a unix text file is being accessed?

I am writing a script that periodically reads in data from a text file. The only issue is that, that text file is periodically updated (appended to) by another script. I am using perl in UNIX environment. How can I check if that text file is being accessed, so I can wait until it is no longer being... (6 Replies)
Discussion started by: rickylui
6 Replies
Login or Register to Ask a Question