Re: howto execute only one time?

From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 01/15/04


Date: 15 Jan 2004 15:04:17 GMT

On Thu, 15 Jan 2004 at 08:49 GMT, fengming wrote:
> Hi,
> I've a problem and don't know if this is practable.
> My problem is that some linux shell is keeping execute a command for
> infinite loop. For example: while I execute the "ping" command, Linux
> just keeps executing it and never ends unless you press the "ctrl+c"
> button or you do a "ps ax|grep ping" and kill that PID.
> Does any one know how can I execute such commands for only one time?
> Please give me some suggestions.

    With the specific example, ping, most implementations (well, GNU,
    FreeBSD and NetBSD) have a -c option to set the number of pings
    sent, e.g., to send two pings:

ping -c2

    If your version of pings doesn't have the -c option, or you want
    to do something similar with another command, redirect the output
    to a pipeline which reads the output. For example, to just send
    one ping:

ping | {
  read header
  read ping_info
  echo $header
  echo $ping_info
}

    The first command will exit when it receives the signal that the
    receiving command has terminated.

-- 
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License