script question

Rick Stevens rstevens at vitalstream.com
Thu Jan 6 18:34:41 UTC 2005


GoijI P wrote:
> can this script terminate a job or program , MyLinuxProgram, that runs 
> on NFS server but started from NFS client PCs?.
> 
> pkill script:
> #!/bin/sh
> #usage: pkill MyLinuxProgram
> for X in `ps acx | grep -i $1 | awk {'print $1'}`; do
>  kill $X;
> done

Only if it's run as the root user or you use "sudo kill $X" and allow
the user running it access to the kill routine.

There's already a script that root can run to kill off any given
program: /usr/bin/killall.  See the man page for it.

> Secondly, can this script logoff all bash NFS client user(s) logged in 
> the NFS server?:
> 
> #!/bin/ksh
> #usage: killuser2 all
> #       =============
> #
> # verify arg1 'all'
> if [ "$1" != "all" ]; then echo "killuser2 arg1 must be 'all' "; exit 1; fi
> # - redirect ps -f output to a tmp file
> ps -e -ocomm -opid -oruser >/tmp/psef
> #
> # - open the file & read back into variables for easier manipulation
> exec 3< /tmp/psef            # open file #3
> #
> x=0; y=0
> while read -u3 comm pid ruser
> do if [[ ("$comm" == bash) && ("$ruser" != root) ]]
>       then let x=x+1
>            kill -9 $pid
>            if [[ $? == 0 ]]; then kok=OK; let y=y+1; else kok=NAK; fi
>            echo "#$x kill $comm $pid $ruser - $kok"
>    fi
> done
> exec 3<&-                    # close file #3
> echo "$x kills attempted, $y killed OK $(date)"

Uh, sorta.  It'll kill off any shell not being run by root.  A "kill -9"
is rather abrupt, however.  A normal "kill" (sending a "SIGTERM") is a
better method, as it will allow the programs to exit cleanly, while the
"-9" (SIGKILL) just pulls the rug out from under them.

Besides, NFS clients don't log into an NFS server.  They mount the
exported filesystems.  There is no "logging in" or running of shells 
involved.
----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens at vitalstream.com -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-          "Very funny, Scotty. Now beam down my clothes."           -
----------------------------------------------------------------------




More information about the Redhat-install-list mailing list