Advertisement
Guest User

Untitled

a guest
Sep 8th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.96 KB | None | 0 0
  1. #!/bin/bash
  2. awk=/usr/bin/awk
  3. kill_all_before(){
  4.   echo "Checking for already running script.sh besides me pid=$$"
  5.   pid=$(ps ax -o user,pid,ppid,command | grep -v 'grep' | grep -v 'vi' | grep script.sh | grep user | $awk '{print $2}')
  6.  if [ -n "$pid" ]
  7.   then
  8.     for curr_pid in ${pid[@]}
  9.     do  
  10.        echo "Found $curr_pid already running, are you sure of what you are doing ?"
  11.        if [ $curr_pid != $$ ]
  12.        then  
  13.            echo "Initializing killing sequence for $curr_pid"
  14.            echo "kill -9 $curr_pid"
  15.                 test=$(ps ax -o pid,ppid | grep -v "PID" | $awk '{ print $1 $2 }')
  16.                 echo "$test"
  17.           # for child in $(ps ax -o pid,ppid | $awk '{ if ( $1 eq $pid ) { print $2 }}')
  18.           # do
  19.           #    echo "Killing child process $child because ppid = $curr_pid"
  20.           #    echo "kill -9 $child"
  21.           # done
  22.       fi  
  23.     done
  24.   else
  25.     echo "returning"
  26.    # return
  27.   fi  
  28. }
  29. kill_all_before
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement