How to kill command after x seconds exporting its output to file?


Results 1 to 3 of 3

Thread: How to kill command after x seconds exporting its output to file?

  1. #1
    Join Date
    Apr 2014
    Posts
    34

    How to kill command after x seconds exporting its output to file?

    Hello,

    in bash script i need to use like:
    Code:
    ping xyz.com && sleep 120 && pkill -f xyz.com >> output.txt
    but it dont works.. how it should look like? dont recommend me to use another command like ping -c 50, i want to use sleep in this case. thx

  2. #2
    Join Date
    Jan 2004
    Location
    boston, mass USA
    Posts
    1,878
    the ping command will ping until you stop it or unless you give it a specific number of attempts (-c 50).

    Maybe watch might do it...?

    watch ping && sleep 120 && pkill -f watch >>output.txt

  3. #3
    Join Date
    Jan 2004
    Location
    boston, mass USA
    Posts
    1,878
    No that wont work either.

    but maybe watch -n 120 ping xyz.com ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •