Re: cat command with timeout

2010-06-20 Thread Tzafrir Cohen
On Sun, Jun 20, 2010 at 04:06:51PM +0300, Raz wrote:
> watch -n1 cat lala
> is another possiblity

What for?

This re-runs cat 1 second after it has finished running.

Try:

  watch -n1 'sleep 5; echo hi'

It will refresh the display every 6 seconds.

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

___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: cat command with timeout

2010-06-20 Thread Raz
watch -n1 cat lala
is another possiblity

2010/6/20 Yigal Asnis 

> You can use timeout command, like
> timeout 5 cat ...
> Yigal
>
> --- On *Sat, 6/19/10, Dan Bar Dov * wrote:
>
>
> From: Dan Bar Dov 
> Subject: Re: cat command with timeout
> To: "Ori Idan" 
> Cc: "IGLU Mailing list" 
> Date: Saturday, June 19, 2010, 11:03 PM
>
> Years ago I needed a cat with a timeout argument.
> I modified the cat code. It was very easy (if I remember correctly less
> than one hour of work).
>
> Sadly, I don't have the code.
>
> Good luck.
> Dan
>
> 2010/6/10 Ori Idan 
> http://mc/compose?to=...@helicontech.co.il>
> >
>
>> I have to read lines from serial port, I thought to read them using 'cat'
>> however, since the other unit connected to the serial port, might
>> malfunction and not send anything, I need a timeout to stop reading after
>> few seconds.
>> Does someone know of an alternative to cat with timeout?
>>
>> --
>> Ori Idan
>>
>>
>>
>> ___
>> Linux-il mailing list
>> Linux-il@cs.huji.ac.il <http://mc/compose?to=linux...@cs.huji.ac.il>
>> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>>
>>
>
> -Inline Attachment Follows-
>
>
> ___
> Linux-il mailing list
> Linux-il@cs.huji.ac.il <http://mc/compose?to=linux...@cs.huji.ac.il>
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>
>
>
> ___
> Linux-il mailing list
> Linux-il@cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>
>
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: cat command with timeout

2010-06-20 Thread Yigal Asnis
You can use timeout command, like
timeout 5 cat ...
Yigal

--- On Sat, 6/19/10, Dan Bar Dov  wrote:

From: Dan Bar Dov 
Subject: Re: cat command with timeout
To: "Ori Idan" 
Cc: "IGLU Mailing list" 
Date: Saturday, June 19, 2010, 11:03 PM

Years ago I needed a cat with a timeout argument.I modified the cat code. It 
was very easy (if I remember correctly less than one hour of work).
Sadly, I don't have the code.

Good luck.Dan

2010/6/10 Ori Idan 

I have to read lines from serial port, I thought to read them using 'cat' 
however, since the other unit connected to the serial port, might malfunction 
and not send anything, I need a timeout to stop reading after few seconds.




Does someone know of an alternative to cat with timeout?

-- 
Ori Idan
 




___

Linux-il mailing list

Linux-il@cs.huji.ac.il

http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il





-Inline Attachment Follows-

___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il



  ___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: cat command with timeout

2010-06-19 Thread Dan Bar Dov
Years ago I needed a cat with a timeout argument.
I modified the cat code. It was very easy (if I remember correctly less than
one hour of work).

Sadly, I don't have the code.

Good luck.
Dan

2010/6/10 Ori Idan 

> I have to read lines from serial port, I thought to read them using 'cat'
> however, since the other unit connected to the serial port, might
> malfunction and not send anything, I need a timeout to stop reading after
> few seconds.
> Does someone know of an alternative to cat with timeout?
>
> --
> Ori Idan
>
>
>
> ___
> Linux-il mailing list
> Linux-il@cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>
>
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: cat command with timeout

2010-06-10 Thread Nadav Har'El
On Thu, Jun 10, 2010, Ori Idan wrote about "cat command with timeout":
> I have to read lines from serial port, I thought to read them using 'cat'
> however, since the other unit connected to the serial port, might
> malfunction and not send anything, I need a timeout to stop reading after
> few seconds.
> Does someone know of an alternative to cat with timeout?

It sounds like (but correct me if I'm wrong) that what you're looking for
is't "cat", but rather a way to read a single line in a shell-script, but
give up after a timeout when you didn't get any line. The command for this
is "read", and bash has a -t parameter:

read -t 4 line

reads a single line from the standard input (redirect it with "<" from the
serial port, if you want) into the variable $line, but if in 4 seconds it
doesn't get a line, it gives up.

If you really want cat with a timeout, you can simulate one with a script.
For example (I did *not* test this):

#!/bin/sh
cat /dev/... &
pid=$!
sleep 5
kill $pid

But I'm not sure how exactly this makes sense (when reading from the serial
port, basically cat will never finish, and will always be killed exactly after
5 seconds - even if a line appeared after just 1 second).


-- 
Nadav Har'El| Thursday, Jun 10 2010, 28 Sivan 5770
n...@math.technion.ac.il |-
Phone +972-523-790466, ICQ 13349191 |Time is the best teacher. Unfortunately
http://nadav.harel.org.il   |it kills all its students.

___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: cat command with timeout

2010-06-10 Thread Valery Reznic
cat /dev/your_serial_port > some_file &sleep Xkill $!
Valery
--- On Thu, 6/10/10, Ori Idan  wrote:

From: Ori Idan 
Subject: cat command with timeout
To: "IGLU Mailing list" 
Date: Thursday, June 10, 2010, 10:13 AM

I have to read lines from serial port, I thought to read them using 'cat' 
however, since the other unit connected to the serial port, might malfunction 
and not send anything, I need a timeout to stop reading after few seconds.



Does someone know of an alternative to cat with timeout?

-- 
Ori Idan
 




-Inline Attachment Follows-

___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il



  ___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


cat command with timeout

2010-06-10 Thread Ori Idan
I have to read lines from serial port, I thought to read them using 'cat'
however, since the other unit connected to the serial port, might
malfunction and not send anything, I need a timeout to stop reading after
few seconds.
Does someone know of an alternative to cat with timeout?

-- 
Ori Idan
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il