STDOUT redirect to a FILE, when fuser command is used !!

Hi all,

I have the following script:


#SCRIPT TO CHECK WHO HAS ACCESSED THE LOG/FILE IN PAST 'N' MINUTES, AND MAIL ACCORDINGLY.

MYPATH="/clocal/mqbrkrs/user/mqsiadm/sanjay/"
MAIL_RECIPIENTS="vg517@dcx.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
echo `fuser -uf "$file_dir" | tr -dc "[:digit:]" ` 1>> tempmail.txt
echo " $file_dir is being accessed" >> tempmail.txt

done

cat tempmail.txt | mailx -s "$Subject" "$MAIL_RECIPIENTS"

fuser command returns process id, to the file "tempmail.txt" and also prints the output to the STDOUT., both the outputs are different.

output to the file tempmail.txt :

335936
/clocal/mqbrkrs/user/mqsiadm/sanjay/ is being accessed
594010880672541182872816
/clocal/mqbrkrs/user/mqsiadm/sanjay/AccessMonitor is being accessed
541182
/clocal/mqbrkrs/user/mqsiadm/sanjay/AccessMonitor/AccessLogMonitor_script is being accessed

output to the STDOUT :----------------------------------------------
/clocal/mqbrkrs/user/mqsiadm/sanjay/: c(mqsiadm)
/clocal/mqbrkrs/user/mqsiadm/sanjay/AccessMonitor: c(mqsiadm)c(mqsiadm)c(mqsiadm)c(mqsiadm)
/clocal/mqbrkrs/user/mqsiadm/sanjay/AccessMonitor/AccessLogMonitor_script: (mqsiadm)

I WANT the output of STDOUT should be present in file tempmail.txt.
In the script i have done `command 1>> filename` but its not working. Please give me the solution to this.

Thanks a lot.:b:
Varun

fuser only outputs PIDs to stdout, everything else is sent to stderr.

Try replacing

echo `fuser -uf "$file_dir" | tr -dc "[:digit:]" ` 1>> tempmail.txt

with

fuser -f $file_dir  >> tempmail.txt  2> /dev/null

Hey man,

As you said everything else has to be given to the /dev/null, but then what if I want everything else also to be in the same file "tempmail.txt" ?

Please let me know the solution !!
Thanks

command 2>>file.log 1>>file.log

And I almost forgotten this one:
This is possible that some apps would always write to TTY. Then there is a reason why you have no output on StdOut. In such a case you should dig on the internet how to do it. For example some app could force to write to /dev/tty/some_device....

Another thing:
2>>file.log - this redirects STD ERR
1>>file.log - this redirects STD OUT

So both StdOut and StdErr are 2 different things.

Hey,

I'll appreciate if you'll let me know what are the commands that do so, i.e. writing to /dev/tty/some_device.
And if possible, let me know how to get the tty output into a user defined file(s) ?

Thanks for the guidence and sharing the knowledge.

Varun.:b:

Really, I don't have any idea how to do it. I never tried such a thing.
I could only give you some example script to experiment with:

#!/bin/ksh
# Terminal
echo "tty" >>/dev/tty
# StdOut
print -u1 "fd1"
# StdErr
print -u2 "fd2"
return 0

It should write 'fd1' to stdout, 'fd2' to stderr and 'tty' to the terminal.
So

script.sh 1>StdOut.txt 2>StdErr.txt

should still print 'tty' text to your terminal.
Maybe someone else could help you.