Hey all,
following is the script :
As I am first logging using my login id(t007) and then I am using "su" to switch the user using generic login id(mqsiadm). Using this script I am trying to find out who accessed the file in last few minutes{originally first user(t007)}.
Am using awk in for loop statement, please let me know I am on the right track or not !!
I am using korn shell, will "$?" work, in this ???
Let me know syntactically Iam right or wrong ?
------------------------------------------------------------------------
## List all the files which one accessed since last 1 min #####
MYPATH="/clocal/mqbrkrs/user/mqsiadm/sanjay/"
MAIL_RECIPIENTS="vg@acx.com"
Subject=":: File(s) accessed/touched in last few minutes ::"
>tempmail.txt
>tempfind.txt
for file_dir in `find $MYPATH -amin -1`
do
echo `fuser -uf "$file_dir" ` >> tempmail.txt
ps -ef | grep "\-ksh" | awk '$8 !~ /grep/ { printf "%s %s %s %s %s\n", $1, $2, $3, $5, $8 ; }' >> tempfind.txt
for pid_var in `awk '$1 !~ /t[a-zA-Z0-9]*/ { printf "%s\n", $2 ;}' tempfind.txt`
do
var=`grep $pid_var "tempmail.txt"`
if [ "$?" -eq "0" ] ; then
awk '$pid_var { printf "%s", $3 ; }' tempfind.txt | awk '$1 !~ /m[a-zA-Z]*/ { printf "%s\t%s\t%s\t%s\t%s\n", $1, $2, $3, $4, $5 ;}' >> tempmail.txt
fi
done
echo " $file_dir is being accessed" >> tempmail.txt
done
-----------------------------------------------------------------------
Thnks
Varun.