Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Kill unwanted pids Script

Posted on 2005-02-25
17
Medium Priority
?
459 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

572 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