substring ??

I execute command on this file and it gives o/p like this.

COMMAND $ fuser -f /clocal/sanjay/AccessMonitor

/clocal/sanjay/AccessMonitor: 1368322c

To truncate 'c', i used tr -dc "[:digit:]\n" but then it does't give 1368322 as O/P.

Any help ??

What is the input to the tr command ?

For me that tr command works fine.

[/tmp]$ echo 123abc | tr -dc "[:digit:]\n"
123
[/tmp]$ 

pid = ''
fuser -f /clocal/sanjay/AccessMonitor > tempfind.txt
pid = cat tempfind.txt | tr -dc "[:digit:]\n"
echo "$pid"

When prompt I run the above command, it gives....
$ fuser -f /clocal/AccessMonitor
/clocal/AccessMonitor: 1368322c

Now I want the no. (without ant character) into the variable pid (given above).

Any idea ??

Can you rectify problem in the following script ??

MYPATH="/clocal/Sanjay/"
MAIL_RECIPIENTS="abcx@zzz.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" > tempfind.txt
pid = cat tempfind.txt | tr -dc "[:digit:]\n"
echo "$pid"

### 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 -w "$pid" | awk '{ print $1 }'`
echo " $file_dir access by the $user " >> tempmail.txt
done

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

Once red faced commands will run successfully, means task is achieved.
Now, in variable pid, i am not getting any thing. I want the process no. related to the file accessed, using fuser command. As shown above.

Any help will be appreciable. !!
:b:

fuser -f "$file_dir" > tempfind.txt
pid=$(tr -dc "[:digit:]\n" < tempfind.txt)

Try :

pid=`cat tempfind.txt | tr -dc "[:digit:]"`

Or

pids=`fuser -f "$file_dir" | tr -dc "[:digit:]"`

Jean-Pierre.

Thanks vino.
Don;t you think that to redirect the contents from the tempfind.txt file, unix creates a saperate process with unique Porcess id. And to truncate it creates another process with unique process id.
I think above command will club the process ids. (of all the processes used in above command) to one id, hence this clubbed id won;t be able get from ps table.

Its not working, means not giving the name of the user from the ps table according to the process id.

Please check it !!
Thanks in advance !!:b:

The following command gives the list of users accessing the file :

users=$(fuser -u -f "$file_dir" 2>&1 | sed 's/[^(]*(\([^)]*\))/\1 /g')

Jean-Pierre.