begin with a script testing if a program is running

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
enhu
Posts: 302
Joined: Wed 27 May 2009, 02:13
Contact:

begin with a script testing if a program is running

#1 Post by enhu »

i'm trying to test whether wget is working still or not.

while [ wget is still running ] <----- but how should this look please.?
do
codes
done

User avatar
RetroTechGuy
Posts: 2947
Joined: Tue 15 Dec 2009, 17:20
Location: USA

Re: begin with a script testing if a program is running

#2 Post by RetroTechGuy »

enhu wrote:i'm trying to test whether wget is working still or not.

while [ wget is still running ] <----- but how should this look please.?
do
codes
done
Update: how about something like (damn "'" versus "`"):

Code: Select all

while [ `ps -C wget | wc -l` != "1"]
do
ps -C wget | wc -l
sleep 1
done
The "ps -C wget" will return 2 lines when wget is running, and one line otherwise.

User avatar
enhu
Posts: 302
Joined: Wed 27 May 2009, 02:13
Contact:

#3 Post by enhu »

thanks
interesting and looks better. i might not send it to /dev/null instead

User avatar
enhu
Posts: 302
Joined: Wed 27 May 2009, 02:13
Contact:

#4 Post by enhu »

change my mind. or do i have to put it in /null ?
i still don't know how to put it in dev/null :D

any suggestions?

i've trying to create a script that will terminate the program once its running :D

so maybe

Code: Select all

if [ `ps -C wget | wc -l` == "1" ] > /dev/null
then
echo do nothing

elif [ `ps -C wget | wc -l` != "1" ];then
  
   terminate
else
something else
fi
any assistance please

User avatar
enhu
Posts: 302
Joined: Wed 27 May 2009, 02:13
Contact:

#5 Post by enhu »

can't even find the dev/null

User avatar
RetroTechGuy
Posts: 2947
Joined: Tue 15 Dec 2009, 17:20
Location: USA

#6 Post by RetroTechGuy »

enhu wrote:can't even find the dev/null
That should be "/dev/null"

It is a "device", and so the "null device" is located in the /dev/ folder.

I just checked, it is there.
[url=http://murga-linux.com/puppy/viewtopic.php?t=58615]Add swapfile[/url]
[url=http://wellminded.net63.net/]WellMinded Search[/url]
[url=http://puppylinux.us/psearch.html]PuppyLinux.US Search[/url]

User avatar
enhu
Posts: 302
Joined: Wed 27 May 2009, 02:13
Contact:

#7 Post by enhu »

there's still no /dev/null in this puppy lucid

can't find it

User avatar
RetroTechGuy
Posts: 2947
Joined: Tue 15 Dec 2009, 17:20
Location: USA

#8 Post by RetroTechGuy »

enhu wrote:there's still no /dev/null in this puppy lucid

can't find it
I typically run 4.3.1

But, I just booted my 5.1.1 CD, opened rxvt, and typed:

Code: Select all

ls /dev/null
That operation shows it as "existing"

I just "cat"-ed a file onto it ("cat junk > /dev/null"), and it performed as expected (i.e. no error messages).

Open rxvt, and confirm that something didn't get messed up in your filesystem (does /dev/null show up in the directory list). You could also do this from the Puppy GUI, by browsing to /dev/ and see if the file "null" exists there.

I haven't tested your script code, but if you are getting errors from the code shown, I suspect that something about your code is incorrect, not /dev/null (error messages are often "obscure" and don't necessarily report the true source of the problem).
[url=http://murga-linux.com/puppy/viewtopic.php?t=58615]Add swapfile[/url]
[url=http://wellminded.net63.net/]WellMinded Search[/url]
[url=http://puppylinux.us/psearch.html]PuppyLinux.US Search[/url]

User avatar
RetroTechGuy
Posts: 2947
Joined: Tue 15 Dec 2009, 17:20
Location: USA

#9 Post by RetroTechGuy »

enhu wrote:change my mind. or do i have to put it in /null ?
i still don't know how to put it in dev/null :D

any suggestions?

i've trying to create a script that will terminate the program once its running :D

so maybe

Code: Select all

if [ `ps -C wget | wc -l` == "1" ] > /dev/null
then
echo do nothing

elif [ `ps -C wget | wc -l` != "1" ];then
  
   terminate
else
something else
fi
any assistance please
OK, looking at this... Why does it need /dev/null at all? I also think that is not the right location for use, if the code did need it.

You are performing an "if" test, which should produce no user-visible output, it should only determine which way the choice "branches".

BTW, I think that your 3rd "option" cannot happen. Your operand is either "=1" or "not = 1", so the last "else" means...what?....

It is possible that if you clean up these 2 issues, the code will work (sorry, I'm not an expert at bash coding -- I can't tell by inspection)
[url=http://murga-linux.com/puppy/viewtopic.php?t=58615]Add swapfile[/url]
[url=http://wellminded.net63.net/]WellMinded Search[/url]
[url=http://puppylinux.us/psearch.html]PuppyLinux.US Search[/url]

PANZERKOPF
Posts: 282
Joined: Wed 16 Dec 2009, 21:38
Location: Earth

Re: begin with a script testing if a program is running

#10 Post by PANZERKOPF »

enhu wrote:i'm trying to test whether wget is working still or not.
while [ wget is still running ] <----- but how should this look please.?
do
codes
done
You can use pidof. "pidof process_name". It returns "false" if process not found.
SUUM CUIQUE.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

Re: begin with a script testing if a program is running

#11 Post by jpeps »

PANZERKOPF wrote:
enhu wrote:i'm trying to test whether wget is working still or not.
while [ wget is still running ] <----- but how should this look please.?
do
codes
done
You can use pidof. "pidof process_name". It returns "false" if process not found.
while [ `pidof wget` ]; do

User avatar
enhu
Posts: 302
Joined: Wed 27 May 2009, 02:13
Contact:

#12 Post by enhu »

thanks..

is the PID of a running application a file?

i seem can't test it with test operators.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#13 Post by jpeps »

enhu wrote:thanks..

is the PID of a running application a file?

i seem can't test it with test operators.
PID is a number; try "ps"

User avatar
enhu
Posts: 302
Joined: Wed 27 May 2009, 02:13
Contact:

#14 Post by enhu »

okay so i did try this just to test

Code: Select all

#!/bin/bash
APP=`pidof wget`

if [ $APP == "" ]; then
	echo do nothing
fi
after running it returns an error saying

line 4 [: == : unary operator expected?

so what kind of file are PIDs?

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#15 Post by jpeps »

REMOVED
Last edited by jpeps on Sat 13 Nov 2010, 01:31, edited 1 time in total.

User avatar
RetroTechGuy
Posts: 2947
Joined: Tue 15 Dec 2009, 17:20
Location: USA

#16 Post by RetroTechGuy »

enhu wrote: so what kind of file are PIDs?
PIDs are Process IDentifiers (a number which is created by the OS to identify a running process)
[url=http://murga-linux.com/puppy/viewtopic.php?t=58615]Add swapfile[/url]
[url=http://wellminded.net63.net/]WellMinded Search[/url]
[url=http://puppylinux.us/psearch.html]PuppyLinux.US Search[/url]

Post Reply