Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with fuser within shell Scripts. 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
0
0
DE
Folks,

it's driving me crazy again !!!

Following problem:

We're using Shell Scripts to start/stop applications on our servers.
Some of them include unmounting several filesystems as well.

Now, there are some systems where - after shutting down the application - several processes remain active, preventing us from doing an umount.

The idea was to simply use

Code:
fuser -ck /name_of_filesystem

However this is not working. No matter how often we repeat the command within the script.

But (!) if I enter the commands

Code:
fuser -ck /name_of_filesystem
umount /name_of_filesystem

directly over the command line everything is fine.

Any idea what's wrong here ?

Another approach was to fetch the PIDs from

Code:
fuser -cv /name_of_filesystem

and then do something like

Code:
kill -9 $PIDs

but the output is extremely weird and I haven't been able to grab the PIDs from it ...

Regards,
Thomas
 
However this is not working
What is the current directory at the time the script launches the fuser command ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If not crontab I think the directory is /root/ ...
 
You don't have to think but to know ...
Use the pwd command before the fuser to be sure.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
but the output is extremely weird
What is a typical output of this ?
fuser -c /name_of_filesystem

I'm pretty sure that a simple awk program may grab the PIDs

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here's the problem:

Code:
fuser -cv /fs

Code:
                     USER        PID ACCESS COMMAND
/fs:                 me          462 F.ce. cat
                     me          493 F.ce. ls
                     me         1913 F.ce. smb

To get rid of the /fs: at the beginning i tried

Code:
fuser -cv /fs | cut -c22-

That's where it started to become weird because the output looked like this:

Code:
462 493 1913

Something similar happens when I try

Code:
fuser -cv /fs > /tmp/test.txt

Here I get the following on the screen:

Code:
                     USER        PID ACCESS COMMAND
/fs:                 me        F.ce. cat
                     me        F.ce. ls
                     me        F.ce. smb

And the content of /tmp/test.txt contains only

Code:
462 493 1913

Regards,
Thomas
 
I asked for the output of fuser -c /fs (NO v option)
 
That's

Code:
/fs:    462ce 493ce 1913ce
 
So, you wanted this ?
Code:
PIDs=$(fuser -c /fs | awk '{for(i=2;i<=NF;++i){sub(/[^0-9]*$/,"",$i);print $i}}')
kill -9 $PIDs

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The odd thing about the [tt]fuser[/tt] command is that some of the output line goes to [tt]stdout[/tt] and some goes to [tt]stderr[/tt]. That's what's causing the confusion. You can get just the PIDs by filtering out [tt]stderr[/tt]. This would do it...

Code:
kill -9 `fuser /fs 2>/dev/null`

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top