Re: need help on shell programming

2009-03-08 Thread Tzafrir Cohen
On Sun, Mar 08, 2009 at 08:50:25PM +0100, Michael Wagner wrote:

> -+
> #! /bin/bash |
>  |
> if [ $(pgrep -x script.sh) ]; then 

Re: need help on shell programming

2009-03-08 Thread Michael Pobega
On Sun, Mar 08, 2009 at 08:50:25PM +0100, Michael Wagner wrote:
> * Michael Pobega  08.03.2009
>  
> > #! /bin/sh
> > 
> > if [ $(ps aux | grep script.sh | grep -v grep) ]; then
> >  
> 
> Hello Michael,
> 
> what about "pgrep"?
> 
> -+
> #! /bin/bash |
>  |
> if [ $(pgrep -x script.sh) ]; then 

Re: need help on shell programming

2009-03-08 Thread Michael Wagner
* Michael Pobega  08.03.2009
 
> #! /bin/sh
> 
> if [ $(ps aux | grep script.sh | grep -v grep) ]; then
>  

Hello Michael,

what about "pgrep"?

-+
#! /bin/bash |
 |
if [ $(pgrep -x script.sh) ]; then 

Re: need help on shell programming

2009-03-07 Thread Michael Pobega
On Thu, Feb 26, 2009 at 04:54:28PM -0500, Long Wind wrote:
> I want a script.
> The script run a command, wait one minute,
> then run the command again, wait one minute again
> ... again and again ...
> 
> Thanks!
> 

Just to bring this back up, you can use a mix of shell programming and
Cronjobs. For example, run your job like so;

*/1 * * * * script.sh

and have the script do some process checking:

#! /bin/sh

if [ $(ps aux | grep script.sh | grep -v grep) ]; then
 

That will make sure it runs every minute, without overlapping itself.
When I write code that needs to be run a preset amount of time, I
generally try to find a way to use Cron -- why recreate what is already
available?

-- 
  http://pobega.wordpress.com
http://identica/pobega


signature.asc
Description: Digital signature


Re: need help on shell programming

2009-03-03 Thread Joe McDonagh
Why is it not the 'best' idea? Infinite loops can be used to your 
advantage. It's already been remarked that cron will not work because it 
is fixed-frequency. That means OP will have to start maintaining state 
via files to avoid race conditions.


An infinite while;do;done construct can be interrupted by a SIGINT 
anyways. A well-constructed shell script will trap this signal and clean 
up whatever dirt it's left behind for finally dying. The while [ 1 -eq 1 
]; answer is semantically correct, but using while true; looks nicer.


Raphael Faria wrote:


i dont think that script with an eternal loop is the best ideia. If u 
want keep  this script running for a long time ( even when ur user is 
loged out, u will need a screen desatached [ screen ^a  ^d]).  My 
advice will be that u make this script and set a rule at ur crontab 
for every min:


#crontab -e

(put this line if u need taht script to run every min)
* *  * *   *  ./path/script


hope that helps u,



2009/3/1 Olaf Reitmaier Veracierta >


while [ 1 -eq 1 ]; then
  
  sleep 60
done

Boyd Stephen Smith Jr. wrote:

On Thursday 26 February 2009 18:35:01 Mike Castle wrote:

On Thu, Feb 26, 2009 at 4:29 PM, Michael Pobega
mailto:pob...@gmail.com>> wrote:

On Thu, Feb 26, 2009 at 04:54:28PM -0500, Long Wind wrote:

I want a script.
The script run a command, wait one minute,
then run the command again, wait one minute again
... again and again ...

Sounds like a job for Cron!

It depends on how long the job takes, and what the
requirements are.

They did seem to imply they want to wait 60 seconds
between the end of
one run to the start of the next one, as opposed to
running every 60
seconds regardless.


The OP says they want fixed-delay.  Cron is for
fixed-frequency.  A script that schedules itself as an "at"
job as it's last command is another way to handle fixed-delay.

If the job takes 45 seconds, it could be a pretty
substantial semantic
difference.


Yep.


-- 
--

  "You don't know where your shadow will fall",
   Somebody.-
--
 Ing. Olaf Reitmaier Veracierta mailto:ola...@gmail.com>>
--
 http://olafrv.googlepages.com (Personal Webpage)
 http://olafrv.blogspot.com (Technical Blog)
--


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org

 with a subject of
"unsubscribe". Trouble? Contact listmas...@lists.debian.org





--
Raphael Ottoni S M de Faria


There is no spoon...



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org




Re: need help on shell programming

2009-03-03 Thread Raphael Faria
i dont think that script with an eternal loop is the best ideia. If u want
keep  this script running for a long time ( even when ur user is loged out,
u will need a screen desatached [ screen ^a  ^d]).  My advice will be that u
make this script and set a rule at ur crontab for every min:

#crontab -e

(put this line if u need taht script to run every min)
* *  * *   *  ./path/script


hope that helps u,



2009/3/1 Olaf Reitmaier Veracierta 

> while [ 1 -eq 1 ]; then
>   
>   sleep 60
> done
>
> Boyd Stephen Smith Jr. wrote:
>
>> On Thursday 26 February 2009 18:35:01 Mike Castle wrote:
>>
>>> On Thu, Feb 26, 2009 at 4:29 PM, Michael Pobega 
>>> wrote:
>>>
 On Thu, Feb 26, 2009 at 04:54:28PM -0500, Long Wind wrote:

> I want a script.
> The script run a command, wait one minute,
> then run the command again, wait one minute again
> ... again and again ...
>
 Sounds like a job for Cron!

>>> It depends on how long the job takes, and what the requirements are.
>>>
>>> They did seem to imply they want to wait 60 seconds between the end of
>>> one run to the start of the next one, as opposed to running every 60
>>> seconds regardless.
>>>
>>
>> The OP says they want fixed-delay.  Cron is for fixed-frequency.  A script
>> that schedules itself as an "at" job as it's last command is another way to
>> handle fixed-delay.
>>
>>  If the job takes 45 seconds, it could be a pretty substantial semantic
>>> difference.
>>>
>>
>> Yep.
>>
>
> --
> --
>   "You don't know where your shadow will fall",
>Somebody.-
> --
>  Ing. Olaf Reitmaier Veracierta 
> --
>  http://olafrv.googlepages.com (Personal Webpage)
>  http://olafrv.blogspot.com (Technical Blog)
> --
>
>
> --
> To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a
> subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
>
>


-- 
Raphael Ottoni S M de Faria


There is no spoon...


Re: need help on shell programming

2009-02-28 Thread Tzafrir Cohen
On Sun, Mar 01, 2009 at 01:32:32AM -0430, Olaf Reitmaier Veracierta wrote:
> Sorry mismatch "then" with "do"...
>
> while [ 1 -eq 1 ]; do

Useless use of test. Use 'true' or ':' instead.

You can save a few cycles (mostly of parsing, I guess :-) [1]

>
>sleep 60
> done

[1] http://xkcd.com/541/

-- 
Tzafrir Cohen | tzaf...@jabber.org | VIM is
http://tzafrir.org.il || a Mutt's
tzaf...@cohens.org.il ||  best
ICQ# 16849754 || friend


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Re: need help on shell programming

2009-02-28 Thread Olaf Reitmaier Veracierta

Sorry mismatch "then" with "do"...

while [ 1 -eq 1 ]; do
   
   sleep 60
done

Boyd Stephen Smith Jr. wrote:

On Thursday 26 February 2009 18:35:01 Mike Castle wrote:

On Thu, Feb 26, 2009 at 4:29 PM, Michael Pobega  wrote:

On Thu, Feb 26, 2009 at 04:54:28PM -0500, Long Wind wrote:

I want a script.
The script run a command, wait one minute,
then run the command again, wait one minute again
... again and again ...

Sounds like a job for Cron!

It depends on how long the job takes, and what the requirements are.

They did seem to imply they want to wait 60 seconds between the end of
one run to the start of the next one, as opposed to running every 60
seconds regardless.


The OP says they want fixed-delay.  Cron is for fixed-frequency.  A script 
that schedules itself as an "at" job as it's last command is another way to 
handle fixed-delay.



If the job takes 45 seconds, it could be a pretty substantial semantic
difference.


Yep.


--
--
   "You don't know where your shadow will fall",
Somebody.-
--
 Ing. Olaf Reitmaier Veracierta 
--
 http://olafrv.googlepages.com (Personal Webpage)
 http://olafrv.blogspot.com (Technical Blog)
--


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org




Re: need help on shell programming

2009-02-28 Thread Olaf Reitmaier Veracierta

while [ 1 -eq 1 ]; then
   
   sleep 60
done

Boyd Stephen Smith Jr. wrote:

On Thursday 26 February 2009 18:35:01 Mike Castle wrote:

On Thu, Feb 26, 2009 at 4:29 PM, Michael Pobega  wrote:

On Thu, Feb 26, 2009 at 04:54:28PM -0500, Long Wind wrote:

I want a script.
The script run a command, wait one minute,
then run the command again, wait one minute again
... again and again ...

Sounds like a job for Cron!

It depends on how long the job takes, and what the requirements are.

They did seem to imply they want to wait 60 seconds between the end of
one run to the start of the next one, as opposed to running every 60
seconds regardless.


The OP says they want fixed-delay.  Cron is for fixed-frequency.  A script 
that schedules itself as an "at" job as it's last command is another way to 
handle fixed-delay.



If the job takes 45 seconds, it could be a pretty substantial semantic
difference.


Yep.


--
--
   "You don't know where your shadow will fall",
Somebody.-
--
 Ing. Olaf Reitmaier Veracierta 
--
 http://olafrv.googlepages.com (Personal Webpage)
 http://olafrv.blogspot.com (Technical Blog)
--


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org




Re: need help on shell programming

2009-02-27 Thread Boyd Stephen Smith Jr.
On Thursday 26 February 2009 18:35:01 Mike Castle wrote:
> On Thu, Feb 26, 2009 at 4:29 PM, Michael Pobega  wrote:
> > On Thu, Feb 26, 2009 at 04:54:28PM -0500, Long Wind wrote:
> >> I want a script.
> >> The script run a command, wait one minute,
> >> then run the command again, wait one minute again
> >> ... again and again ...
> > Sounds like a job for Cron!
>
> It depends on how long the job takes, and what the requirements are.
>
> They did seem to imply they want to wait 60 seconds between the end of
> one run to the start of the next one, as opposed to running every 60
> seconds regardless.

The OP says they want fixed-delay.  Cron is for fixed-frequency.  A script 
that schedules itself as an "at" job as it's last command is another way to 
handle fixed-delay.

> If the job takes 45 seconds, it could be a pretty substantial semantic
> difference.

Yep.
-- 
Boyd Stephen Smith Jr.   ,= ,-_-. =.
b...@iguanasuicide.net  ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/\_/



signature.asc
Description: This is a digitally signed message part.


Re: need help on shell programming

2009-02-26 Thread Alex Samad
On Thu, Feb 26, 2009 at 11:01:37PM +0100, Sjors Gielen wrote:
> Kumar Appaiah schreef:
>> On Thu, Feb 26, 2009 at 3:54 PM, Long Wind wrote:
>>> I want a script.
>>> The script run a command, wait one minute,
>>> then run the command again, wait one minute again
>>> ... again and again ...
>>
>>  while [[ 1 < 2 ]]; do echo Hello; sleep 60;done
>
> [[ 1 < 2 ]] ? My suggestion:
>
> while :; do
>   echo Hello;
>   sleep 60;

why the ; at the of the echo and sleep

> done
>
>> Replace "echo Hello" with your command.
>>
>> HTH.
>>
>> Kumar
>
> Sjors
>
>
> -- 
> To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a 
> subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
>
>

-- 
Replace with same type.


signature.asc
Description: Digital signature


Re: need help on shell programming

2009-02-26 Thread Mike Castle
On Thu, Feb 26, 2009 at 4:29 PM, Michael Pobega  wrote:
> On Thu, Feb 26, 2009 at 04:54:28PM -0500, Long Wind wrote:
>> I want a script.
>> The script run a command, wait one minute,
>> then run the command again, wait one minute again
>> ... again and again ...
>>
>> Thanks!
>>
>>
>
> Sounds like a job for Cron!

It depends on how long the job takes, and what the requirements are.

They did seem to imply they want to wait 60 seconds between the end of
one run to the start of the next one, as opposed to running every 60
seconds regardless.

If the job takes 45 seconds, it could be a pretty substantial semantic
difference.

mrc


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Re: need help on shell programming

2009-02-26 Thread Michael Pobega
On Thu, Feb 26, 2009 at 04:54:28PM -0500, Long Wind wrote:
> I want a script.
> The script run a command, wait one minute,
> then run the command again, wait one minute again
> ... again and again ...
> 
> Thanks!
> 
> 

Sounds like a job for Cron!

-- 
  http://pobega.wordpress.com
http://identica/pobega


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Re: need help on shell programming

2009-02-26 Thread Kumar Appaiah
On Thu, Feb 26, 2009 at 4:01 PM, Tzafrir Cohen wrote:
>>  while [[ 1 < 2 ]]; do echo Hello; sleep 60;done
>
> Not only bashism, but also not as readable.
>
>>
>> Replace "echo Hello" with your command.
>
>
> #!/bin/sh
> while true
> do
>  your command
>  sleep 60
> done

Thanks for the improved one. The above snippet is from code I had
written four years ago, when I was learning bash scripting... I've
gone and changed it in my script too. :-)

Kumar
-- 
Kumar


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Re: need help on shell programming

2009-02-26 Thread Sjors Gielen

Kumar Appaiah schreef:

On Thu, Feb 26, 2009 at 3:54 PM, Long Wind wrote:

I want a script.
The script run a command, wait one minute,
then run the command again, wait one minute again
... again and again ...


 while [[ 1 < 2 ]]; do echo Hello; sleep 60;done


[[ 1 < 2 ]] ? My suggestion:

while :; do
echo Hello;
sleep 60;
done


Replace "echo Hello" with your command.

HTH.

Kumar


Sjors


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org




Re: need help on shell programming

2009-02-26 Thread Tzafrir Cohen
On Thu, Feb 26, 2009 at 03:56:54PM -0600, Kumar Appaiah wrote:
> On Thu, Feb 26, 2009 at 3:54 PM, Long Wind wrote:
> > I want a script.
> > The script run a command, wait one minute,
> > then run the command again, wait one minute again
> > ... again and again ...
> 
>  while [[ 1 < 2 ]]; do echo Hello; sleep 60;done

Not only bashism, but also not as readable.

> 
> Replace "echo Hello" with your command.


#!/bin/sh
while true
do
  your command
  sleep 60
done

-- 
Tzafrir Cohen | tzaf...@jabber.org | VIM is
http://tzafrir.org.il || a Mutt's
tzaf...@cohens.org.il ||  best
ICQ# 16849754 || friend


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Re: need help on shell programming

2009-02-26 Thread Gilles Mocellin
On Thu, Feb 26, 2009 at 04:54:28PM -0500, Long Wind wrote:
> I want a script.
> The script run a command, wait one minute,
> then run the command again, wait one minute again
> ... again and again ...

Look at the "watch" package/program.


signature.asc
Description: Digital signature


(SOLVED)Re: need help on shell programming

2009-02-26 Thread Long Wind
Thank you very much!

On 2/26/09, Kumar Appaiah  wrote:
> On Thu, Feb 26, 2009 at 3:54 PM, Long Wind wrote:
>  > I want a script.
>  > The script run a command, wait one minute,
>  > then run the command again, wait one minute again
>  > ... again and again ...
>
>
>  while [[ 1 < 2 ]]; do echo Hello; sleep 60;done
>
>  Replace "echo Hello" with your command.
>
>  HTH.
>
>  Kumar
>  --
>  Kumar
>
>
>
>  --
>  To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
>  with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
>
>


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Re: need help on shell programming

2009-02-26 Thread Kumar Appaiah
On Thu, Feb 26, 2009 at 3:54 PM, Long Wind wrote:
> I want a script.
> The script run a command, wait one minute,
> then run the command again, wait one minute again
> ... again and again ...

 while [[ 1 < 2 ]]; do echo Hello; sleep 60;done

Replace "echo Hello" with your command.

HTH.

Kumar
-- 
Kumar


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org