Check who is writing to a file? (pid)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Check who is writing to a file? (pid)
# 1  
Old 10-29-2010
Check who is writing to a file? (pid)

Hello,

is there a way to check who is writing to a file? (pid)

Like someone starts a ftp transfer, is uploading a file and I'd need to know which pid is actually writing to it.

Or is there a way to check which file a process is currently accessing?

Greetings and thanks for all your help in advance!
# 2  
Old 10-29-2010
Try the unix "fuser" command.
# 3  
Old 10-29-2010
Okey that works, but it has a wierd format.

What's the best way to select the PID or put into a var?

I need something like:

Code:
PID=`fuser $file | awk/sed....?`
if [ "$PID" != "" ]; then
kill $PID
fi

# 4  
Old 10-29-2010
Have a look at the man page man fuser
options -u and -k
# 5  
Old 10-30-2010
Please post the output from "fuser" on a typical file which is open for write. Depending on your O/S the output can appear jumbled unless you only process the output from one channel.

Code:
fuser filename 1>/dev/null
fuser filename 2>/dev/null

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Pid file and process check

Hello, I am running ubuntu14.04 What I am trying to do is restart a process with a shell when pid is dead. I restored pid nr in a file and check with ps aux | grep -v grep | grep $(cat *.pid)| awk '{ print $2 }' While surfing on google, I have found an answer saying that restoring pid in a... (2 Replies)
Discussion started by: baris35
2 Replies

2. Shell Programming and Scripting

Check if PID exists

In a Shell Script what is the most generic way to find in the PID exists or not. If it does not exist how can I echo the user "PID does not exist" & terminate the unix script ? If the command can work on most flavors of operating system the more useful I will find it to be. Current system... (16 Replies)
Discussion started by: mohtashims
16 Replies

3. Shell Programming and Scripting

Writing a script to run weekly/monthly - check for weekday or day-of-the-month

Hi all, I currently have a UNIX file maintenance script that runs daily as a cron job. Now I want to change the script and create functions/sub inside it that runs on a weekly or monthly basis. To run all the scripts' daily maintenance, I want to schedule it in cron as simply maint.sh... (1 Reply)
Discussion started by: newbie_01
1 Replies

4. Shell Programming and Scripting

How to check if a script is writing to a log

Hello, I have various scripts that writes to logs ( >> ) in different directories. I have create a script to automatically check different direcories for different errrors. However I do not want to remove logs if a script is still writing to a log. Is the log file opened for writing when the... (7 Replies)
Discussion started by: drbiloukos
7 Replies

5. Shell Programming and Scripting

Help writing a script check log not update.

:wall:Dear All.:p How to check log size every 10min. by script (not crontab) if log size not change with alert "Log not update" My Path :: /usr/home/logical/mono/log/tplink/ My Log :: mono11_tplink.log , mono12_tplink.log , etc I want oup put. EX. if log not update. . . . Fri Jan ... (1 Reply)
Discussion started by: ooilinlove
1 Replies

6. Shell Programming and Scripting

How to check whether server is up or down by monitoring PID?

we have a server, which becomes down at times and we dont get any notification mail. Can we monitor PID for that server run and create a script to send notification to a mail id? I have URL for the server, which I can use. Please let me know if more information is required from my end to... (2 Replies)
Discussion started by: vandana.parwani
2 Replies

7. Shell Programming and Scripting

Check process running Status with PID

Good day I am fairly new to Shell Scripting. I want a script to check if a process is up by checking the process's PID and then return a value for when it's running which would be 0. If it isn't running it should give any other value that 0. Any Help is appreciated Regards (9 Replies)
Discussion started by: 1nsyz1on
9 Replies

8. Shell Programming and Scripting

Linux: Writing a tricky script to check connectivity

So, first and foremost, I'm having issues with my internet connection. Periodically, the connection drops across the network. The fix is simple enough: restart the modem. However, this gets old when the connection dies out every hour. I can hit my surfboard on 192.168.100.1, and navigate to a... (5 Replies)
Discussion started by: kungfujoe
5 Replies

9. Shell Programming and Scripting

How to check if a pid is alive?

I want to do some operations provided the pid is active. (6 Replies)
Discussion started by: ScriptDummy
6 Replies

10. Shell Programming and Scripting

Script to check status of a PID

i'm just learning scripting, and have been banging my head against this I want to check if my WAS6 java process is running and if so..echo me a messages. If not then echo me a different messages the problem i have is I dont know how to represent a NULL return value. If i grep for a was6... (14 Replies)
Discussion started by: zeekblack
14 Replies
Login or Register to Ask a Question