LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 09-10-2005, 11:45 AM   #1
pass
LQ Newbie
 
Registered: Sep 2005
Distribution: Debian GNU/Linux
Posts: 10

Rep: Reputation: 0
kill/restart process


Hi everyone !

I have a D-Link DSL-G604T router/modem. I'm trying to code a telnet script to restart the internet connection (drop and connect again). The telnet commands in the router are very limited (no 'killall' command, only 'kill') and i don't see an automatic way to find the pppd process id. My question is, is there a way to kill a process by name ? Using "kill pppd" drops me from telnet and process still runs. Killing by id works but i need an automatic way because process id changes of course.

Using ps ax | grep pppd shows the process id but i don't know a way to catch it and kill it. Anyone have any ideas for this ?

Thanks in advance
 
Old 09-10-2005, 12:22 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,289

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
The following should work if you have grep and awk. If you don't have awk, you can use the cut command to do the same thing easily:

Code:
kill `ps aux | grep pppd | grep -v grep | awk '{print $2}'`
 
Old 09-10-2005, 12:39 PM   #3
pass
LQ Newbie
 
Registered: Sep 2005
Distribution: Debian GNU/Linux
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks for the reply btmiller
Unfortanly i don't have none of those commands
Code:
# kill `ps aux | grep pppd | grep -v grep | awk '{print $2}'`
awk: No such file or directory
kill: Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or
kill -l [exitstatus]
# kill `ps aux | grep pppd | grep -v grep | cut '{print $2}'`
cut: No such file or directory
kill: Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or
kill -l [exitstatus]
#
 
Old 09-10-2005, 02:55 PM   #4
JCipriani
Member
 
Registered: Aug 2005
Location: Pittsburgh, PA, USA
Distribution: Redhat 9, OS X 10.4.x, Win2K
Posts: 85

Rep: Reputation: 15
There's apparently various third parties that also make firmware for that router (which may include more useful commands), it looks like there's some links and interesting general info here. What commands and programs do you have available? It looks like, from your above post, you have at least ps and grep. If you do:
Code:
ps ax | grep pppd
The output of that will be the pppd process lines and the first word on the line is the PID. So the only thing left for you to do is to find some command that, given a line of text, outputs the first word (you might possibly be able to take advantage of the fact that the first word is a number). Then you can do:
Code:
kill `ps ax | grep pppd | some_program_that_grabs_that_first_word`
Without knowing what tools are available to you it's hard to give any more info. If you have perl, you can use a script like:
Code:
#!/usr/bin/perl

@plist = `ps ax`;

foreach $_ (@plist) {
    if (/pppd/) {
        @words = split();
        print $words[0];
        exit 0;
    }
}

exit 1;
In which case you would do:
Code:
kill `myscript.pl`
Er... well, I guess you could just put the kill command right in the script as well. Incidently, that was my first (or maybe second) perl script so... if you're one of those crazy perl people, please don't yell at me if I did something silly! It took me a long time to write that...

Jason

Last edited by JCipriani; 09-10-2005 at 02:57 PM.
 
Old 09-10-2005, 04:09 PM   #5
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
if he hasn't got sed, I doubt he'd have perl!
 
Old 09-10-2005, 04:27 PM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 126Reputation: 126
Do you have pidof?

Code:
kill `pidof pppd`
Why don't you tell us what you do have? Perhaps a ls /usr/bin, if there's not too much.
 
Old 09-10-2005, 06:09 PM   #7
pass
LQ Newbie
 
Registered: Sep 2005
Distribution: Debian GNU/Linux
Posts: 10

Original Poster
Rep: Reputation: 0
Good evening gents
Thanks for all the awsers. I don't have perl nor pidof and better to not touch firmware. When i bought the router i tried thousands of firmwares and the one i use atm is the only one i get working with my isp.

Code:
BusyBox v0.61.pre (2004.09.21-02:32+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

# help

Built-in commands:
-------------------
        . : bg break builtin cd chdir continue eval exec exit export
        false fc fg hash help jobs kill local pwd read readonly return
        set setvar shift times trap true type ulimit umask unset wait


# ls /usr/bin
[           cm_logic    dumpleases  nslookup    tftp        wget
cm_cli      cm_monitor  free        passwd      traceroute  whoami
cm_klogd    cm_pc       id          test        tty         yes
#
The way i do so far is using the command 'reboot', which isn't very handy because it restarts the whole system, not only the pppd process
 
Old 09-10-2005, 06:14 PM   #8
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 126Reputation: 126
Oops, I guess I should've also mentioned /bin. Though, come to think of it, doesn't pppd create a .pid or similar file somewhere?
 
Old 09-10-2005, 07:27 PM   #9
pass
LQ Newbie
 
Registered: Sep 2005
Distribution: Debian GNU/Linux
Posts: 10

Original Poster
Rep: Reputation: 0
Hi
Here they are:

Code:
# ls /bin
ash       chmod     dd        grep      login     mv        rm        tar
busybox   chown     df        hostname  ls        ping      sh        touch
cat       cp        echo      kill      mkdir     ps        sleep     true
chgrp     date      false     ln        mount     pwd       sync      umount
#
Nothing very useful i guess Couldn't find .pid files. find and locator also not available.
 
Old 09-10-2005, 08:17 PM   #10
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 126Reputation: 126
Try this really BAD hack.
Code:
ls -R / | grep pppd
To see if stores a pid anywhere.
 
Old 09-10-2005, 08:25 PM   #11
pass
LQ Newbie
 
Registered: Sep 2005
Distribution: Debian GNU/Linux
Posts: 10

Original Poster
Rep: Reputation: 0
Hello once again
Don't think it works... tried to use wget to download pidof and i got an error saying filesystem is read-only.
Seems the only way is like JCipriani said, using a third party program to catch the process id But too hard for me. I guess i'm trying to build a house without bricks.

Last edited by pass; 09-10-2005 at 08:29 PM.
 
Old 09-10-2005, 08:27 PM   #12
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 126Reputation: 126
That's a shame. My command gave no results?
 
Old 09-10-2005, 08:30 PM   #13
pass
LQ Newbie
 
Registered: Sep 2005
Distribution: Debian GNU/Linux
Posts: 10

Original Poster
Rep: Reputation: 0
Code:
# ls -R / | grep pppd
ls: illegal option -- R
BusyBox v0.61.pre (2004.09.21-02:32+0000) multi-call binary

Usage: ls [-1AacCdeFilnpLrSsTtuvwxXk] [filenames...]
 
Old 09-11-2005, 12:16 AM   #14
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 126Reputation: 126
Umm, wow. No -R? Even the BusyBox homepage says there should be a -R. This is definitely not cool.
 
Old 09-11-2005, 02:38 AM   #15
JCipriani
Member
 
Registered: Aug 2005
Location: Pittsburgh, PA, USA
Distribution: Redhat 9, OS X 10.4.x, Win2K
Posts: 85

Rep: Reputation: 15
Oh, right, you have sh. So, if you can run this sh script:
Code:
#!/bin/sh

for a in `ps ax | grep pppd | grep -v grep` ; do
  echo "Killing PID $a..."
  kill $a
  exit 0
done

echo "No process killed."
exit 1
It should do the trick. Each time you run it it will kill one pppd. Sort of a hack, but it works. The "grep -v grep" just filters out the "grep pppd" process from the list (and I'd recommend not putting pppd in the name of the script).

Quote:
Originally posted by eddiebaby1023
if he hasn't got sed, I doubt he'd have perl!
Oh... are sed and perl connected...?

Jason

Last edited by JCipriani; 09-11-2005 at 03:30 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
cannot kill process (kill -9 does not work) mazer13a Linux - General 1 05-27-2005 03:32 PM
Why does imwheel randomly take up 99% of resources until I kill/restart it :(!? SBing Linux - Software 0 07-13-2004 02:28 AM
Must kill pppd and restart for it to work,Mandrake 10.0 SharpyWarpy Mandriva 0 06-10-2004 03:49 AM
Does kill -HUP <id> restart the <id> process? feetyouwell Linux - Software 1 02-15-2004 11:48 PM
Cannot kill process - please help! thomas.nichols Linux - General 16 09-05-2001 07:43 AM

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

All times are GMT -5. The time now is 02:06 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration