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 Wed 22 Oct 2014, 04:10
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 Posts_count   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_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_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_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_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_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_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_website 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Sat 30 Oct 2010, 11:30    Post_subject:  

REMOVED
Edited_time_total
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 2 Posts_count   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:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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