Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 02 Sep 2014, 00:37
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
begin with a script testing if a program is running
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [16 Posts]   Goto page: 1, 2 Next
Author Message
enhu


Joined: 26 May 2009
Posts: 301

PostPosted: Wed 22 Sep 2010, 04:06    Post subject:  begin with a script testing if a program is running  

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
Back to top
View user's profile Send private message Visit poster's website 
RetroTechGuy


Joined: 15 Dec 2009
Posts: 2668
Location: USA

PostPosted: Wed 22 Sep 2010, 09:54    Post subject: Re: begin with a script testing if a program is running  

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:
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.
Back to top
View user's profile Send private message 
enhu


Joined: 26 May 2009
Posts: 301

PostPosted: Wed 22 Sep 2010, 14:07    Post subject:  

thanks
interesting and looks better. i might not send it to /dev/null instead
Back to top
View user's profile Send private message Visit poster's website 
enhu


Joined: 26 May 2009
Posts: 301

PostPosted: Fri 29 Oct 2010, 07:30    Post subject:  

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

any suggestions?

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

so maybe

Code:
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
Back to top
View user's profile Send private message Visit poster's website 
enhu


Joined: 26 May 2009
Posts: 301

PostPosted: Fri 29 Oct 2010, 07:35    Post subject:  

can't even find the dev/null
Back to top
View user's profile Send private message Visit poster's website 
RetroTechGuy


Joined: 15 Dec 2009
Posts: 2668
Location: USA

PostPosted: Fri 29 Oct 2010, 09:56    Post subject:  

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.

_________________
Add swapfile
Back to top
View user's profile Send private message 
enhu


Joined: 26 May 2009
Posts: 301

PostPosted: Fri 29 Oct 2010, 10:54    Post subject:  

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

can't find it
Back to top
View user's profile Send private message Visit poster's website 
RetroTechGuy


Joined: 15 Dec 2009
Posts: 2668
Location: USA

PostPosted: Fri 29 Oct 2010, 11:26    Post subject:  

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:
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).

_________________
Add swapfile
Back to top
View user's profile Send private message 
RetroTechGuy


Joined: 15 Dec 2009
Posts: 2668
Location: USA

PostPosted: Fri 29 Oct 2010, 11:34    Post subject:  

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 Very Happy

any suggestions?

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

so maybe

Code:
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)

_________________
Add swapfile
Back to top
View user's profile Send private message 
PANZERKOPF

Joined: 16 Dec 2009
Posts: 280
Location: Earth

PostPosted: Fri 29 Oct 2010, 18:03    Post subject: Re: begin with a script testing if a program is running  

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.
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Sat 30 Oct 2010, 03:03    Post subject: Re: begin with a script testing if a program is running  

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
Back to top
View user's profile Send private message 
enhu


Joined: 26 May 2009
Posts: 301

PostPosted: Sat 30 Oct 2010, 03:59    Post subject:  

thanks..

is the PID of a running application a file?

i seem can't test it with test operators.
Back to top
View user's profile Send private message Visit poster's website 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Sat 30 Oct 2010, 07:01    Post subject:  

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"
Back to top
View user's profile Send private message 
enhu


Joined: 26 May 2009
Posts: 301

PostPosted: Sat 30 Oct 2010, 08:53    Post subject:  

okay so i did try this just to test


Code:
#!/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?
Back to top
View user's profile Send private message Visit poster's website 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Sat 30 Oct 2010, 11:30    Post subject:  

REMOVED
Last edited by jpeps on Fri 12 Nov 2010, 21:31; edited 1 time in total
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [16 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0759s ][ Queries: 11 (0.0073s) ][ GZIP on ]