Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- awk=/usr/bin/awk
- kill_all_before(){
- echo "Checking for already running script.sh besides me pid=$$"
- pid=$(ps ax -o user,pid,ppid,command | grep -v 'grep' | grep -v 'vi' | grep script.sh | grep user | $awk '{print $2}')
- if [ -n "$pid" ]
- then
- for curr_pid in ${pid[@]}
- do
- echo "Found $curr_pid already running, are you sure of what you are doing ?"
- if [ $curr_pid != $$ ]
- then
- echo "Initializing killing sequence for $curr_pid"
- echo "kill -9 $curr_pid"
- test=$(ps ax -o pid,ppid | grep -v "PID" | $awk '{ print $1 $2 }')
- echo "$test"
- # for child in $(ps ax -o pid,ppid | $awk '{ if ( $1 eq $pid ) { print $2 }}')
- # do
- # echo "Killing child process $child because ppid = $curr_pid"
- # echo "kill -9 $child"
- # done
- fi
- done
- else
- echo "returning"
- # return
- fi
- }
- kill_all_before
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement