?
Solved

Kill unwanted pids Script

Posted on 2005-02-25
17
Medium Priority
?
455 Views
Last Modified: 2013-12-06
Hello experts,
I would like to create a small script for my fedora core 1 server.

I have sendmail working and I don’t want to start spamming like 15
Days ago.

sendmail its running pid is 13640 but sometimes when I type
fuser 25/tcp I see others pids running and I have to kill em
about 5 pids every hour.

Is there anyway to make a script that can kill em except '13640'
thank you in advance
0
Comment
Question by:Xtry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 6
17 Comments
 

Author Comment

by:Xtry
ID: 13405017
I am thinking about something like

fuser 25/tcp
if (PID !=  13640)
 kill -9 PID
 :end

I dont know =/
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13405572
try this .....
-----------------------------------------------------
#/bin/bash

PROCESS=13640
for i in `fuser 25/tcp | awk '{ print $2 }'`
do
    if [ "$i" -ne $PROCESS ]
      kill -9 $i
      echo "killed ... $i"
   fi
done
-----------------------------------------------------

surya.
0
 

Author Comment

by:Xtry
ID: 13405827
This is what im getting

./kill_pids
: command not foundne 2:
'/kill_pids: line 5: syntax error near unexpected token `do
'/kill_pids: line 5: `do
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13405883
#/bin/bash

PROCESS=13640
for i in `/sbin/fuser 25/tcp | awk '{ print $2 }'`
do
    if [ "$i" -ne $PROCESS ]
        then
      kill -9 $i
      echo "killed ... $i"
   fi
done


surya
0
 

Author Comment

by:Xtry
ID: 13405884
./pids
./pids: line 9: syntax error near unexpected token `fi'
./pids: line 9: `   fi'
0
 

Author Comment

by:Xtry
ID: 13405891
sorry I didnt see the last post you did
its working now
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13405907
good!
0
 

Author Comment

by:Xtry
ID: 13405920
when I do '/fuser 25/tcp' I still see the pids running, I think its not working..
0
 

Author Comment

by:Xtry
ID: 13405925
I didnt see any error though
0
 

Author Comment

by:Xtry
ID: 13405947
the output of /sbin/fuser 25/tcp | awk '{ print $2 }'
is 13640

the output of /sbin/fuser 25/tcp
is 13640 17198 17201 17224
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13406008
sorry I got a different output in my machine ...

#/bin/bash

PROCESS=17028
for i in `/sbin/fuser 8001/tcp `
do
    if [ "$i" -ne $PROCESS ]
        then
      kill -9 $i
   fi &> /dev/null
done

try this ...
0
 
LVL 7

Accepted Solution

by:
surya_prabhakar earned 2000 total points
ID: 13406020
ooops!!! that was my script this is yours

#/bin/bash

PROCESS=13640
for i in `/sbin/fuser 25/tcp `
do
    if [ "$i" -ne $PROCESS ]
        then
      kill -9 $i
   fi &> /dev/null
done
0
 

Author Comment

by:Xtry
ID: 13406103
it worked fine ;)
now I dont have to kill the pids every hour?
will that script kill them if they run
0
 

Author Comment

by:Xtry
ID: 13406121
is there anyway to make run that script every 50 secs ?
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13406141
you have to put a cron script which will run every minute

is that ok??
0
 

Author Comment

by:Xtry
ID: 13406145
yeah, its okay.
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses
Course of the Month7 days, 20 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question