LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-23-2014, 05:38 AM   #1
postcd
Member
 
Registered: Oct 2013
Posts: 527

Rep: Reputation: Disabled
How to kill some runnin perl script from bash script?


aim is to kill this script after 120 seconds of running and saving its output to a file. but my command not working and appears not killing the process.

Code:
#!/bin/sh
set -ex

while read domain;do
output=$(/root/tra*/script.pl $domain & pid=$!
sleep 120
pkill -f $domain)
echo "something"
echo "$output" > $domain_outputfile.txt
cat $domain_outputfile.txt
done < domains.txt
any idea why the command is not killed?
 
Old 04-24-2014, 01:03 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Maybe start with a simple version then slowly add to it, this works:

Code:
#!/bin/bash

output=$( ping localhost &
sleep 20
pkill -f ping )

echo "[*] output: $output"
So try just doing the middle bit then adding the extras slowly, it may be that the while loop is the culprit.
 
Old 05-01-2014, 06:00 AM   #3
markseger
Member
 
Registered: Jul 2003
Posts: 244

Rep: Reputation: 26
It it's the ONLY script running under perl, how about "killall /usr/bin/perl"? I have a python script that sometimes starts 50 threads and this technique works like a champ on it. In fact, if others on the system are running their own python scripts it leaves them alone since I'm not running as root so it only kills my processes.

On the other hand if you have to, you could do something like this to get the process pid and then kill it

Quote:
ps aux | grep xxx | grep -v grep | awk '{print $2}'
-mark
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script: Kill a process after fixed time. bruno.miranda Linux - Newbie 8 06-28-2012 08:31 PM
Bash Script: Kill a process after fixed time. bruno.miranda Linux - Newbie 1 06-28-2012 02:48 PM
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-22-2008 11:25 PM
how do i kill a process from inside a bash script? mikaelo Programming 4 05-28-2004 08:51 AM
small bash script to kill a PID flosch Linux - General 3 05-06-2004 09:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration