remove_old_programs.bash 585 Bytes
Newer Older
Rohit Gupta's avatar
Rohit Gupta committed
1
2
3
#!/bin/bash

#$1 programs to be killed and checked
4
5
echo "removing old programs..."
echo "args = $1"
6
7
echo "script name = $0"
filename=$(basename "$0")
8
9
echo "filename = $filename"
echo "programs to be killed...$1"
Rohit Gupta's avatar
Rohit Gupta committed
10

11
12
13
14
15
16
echo "bash PID = $$" 
pid="$$"
echo "pid = $pid"

echo "Killing programs now..."
ps -aux |grep -E -i $1 |awk '{print $2}'| tr '\n' ' ' | sed  "s/$pid/ /" | sudo xargs kill -9 
17

18
19
echo "checking for old programs..."
var=`ps -aux |grep -E -i '$1' |grep -Ev 'grep' | grep -Ev '$filename'`
Rohit Gupta's avatar
Rohit Gupta committed
20

Rohit Gupta's avatar
Rohit Gupta committed
21
22
23
echo $var
if [ -n "$var" ]; then echo 'Match found'; else echo 'Match not found' ;fi