• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

Shell script - timeout command

Scheduled Pinned Locked Moved General pfSense Questions
2 Posts 1 Posters 1.3k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S
    salmonbaytech
    last edited by Aug 8, 2013, 6:45 PM

    any thoughts on a tool that is already installed on pfsense that will do the same thing as the timeout command?
    http://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html

    I have a shell script, that I would like to timeout as a backup to it already exiting on its own.

    1 Reply Last reply Reply Quote 0
    • S
      salmonbaytech
      last edited by Aug 27, 2013, 6:53 PM

      made an SH script to accomplish what I needed. thought I would share it.

      
      #! /bin/sh
      
      timeout=$1
      sleeptime=$2
      command=$3
      
      # test pid is still around
      PIDActive() {
      	pid=$1
      
      	test=`ps -p $pid | grep $pid`
      	if [ -z "$test" ]; then
      		return 1
      	fi
      	return 0
      }
      
      # run command & capture pid
      $command&
      commandpid=$! 
      
      # What happens first? pid exits or timeout
      counter=0
      while PIDActive $commandpid && [ "$counter" -le "$timeout" ]; do
          sleep $sleeptime
          counter=`expr $counter + $sleeptime`
      done
      
      # if we get to this point and the pid is still active, kill it
      PIDActive $commandpid && kill -s KILL  $commandpid
      
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
        This community forum collects and processes your personal information.
        consent.not_received