Hot answers tagged

85

Yes. curl has two options: --connect-timeout and --max-time. Quoting from the manpage: --connect-timeout <seconds> Maximum time in seconds that you allow the connection to the server to take. This only limits the connection phase, once curl has connected this option is of no more use. Since 7.32.0, this option accepts ...


27

What about this: foo=`{ { cat 1>&3; kill 0; } | { sleep 2; kill 0; } } 3>&1` That is: run the output-producing command and sleep in the same process group, a process group just for them. Whichever command returns first kills the whole process group. Would anyone wonder: Yes, the pipe is not used; it's bypassed using the redirections. The ...


27

Use timeout: NAME timeout - run a command with a time limit SYNOPSIS timeout [OPTION] DURATION COMMAND [ARG]... timeout [OPTION] (Just in case, if you don't have this command or if you need to be compatible with very very old shells and have several other utterly specific requirements… have a look at this this question ;-))


20

If GNU timeout is not available you can use expect (Mac OS X, BSD, ... do not usually have GNU tools and utilities by default). ################################################################################ # Executes command with a timeout # Params: # $1 timeout in seconds # $2 command # Returns 1 if timed out 0 otherwise timeout() { time=$1 ...


20

You can place the timeout command in a subshell and make it succeed: ( timeout 10 <command> || true ) | wc -c


12

To cause an exiting connection to timeout you can use iptables. Just enable a DROP rule on the port you want to disable. So to simulate a timeout for your Samaba server, while an active connection is up, execute the following on the server: sudo iptables -A INPUT -p tcp --dport 445 -j DROP The DROP target will not reply with a RST packet or ICMP error ...


11

Potential solution #1 Use the timeout command: $ date Mon May 6 07:35:07 EDT 2013 $ timeout 5 sleep 100 $ date Mon May 6 07:35:14 EDT 2013 You can put a guard into the timeout command as well to kill the process if it hasn't stopped after some period of time too. $ date Mon May 6 07:40:40 EDT 2013 $ timeout -k 20 5 sleep 100 $ date Mon May 6 07:40:...


9

I believe that the idea of the socket being unavailable to a program is to allow any TCP data segments still in transit to arrive, and get discarded by the kernel. That is, it's possible for an application to call close(2) on a socket, but routing delays or mishaps to control packets or what have you can allow the other side of a TCP connection to send data ...


8

Thank you for the clarification. The easiest way to accomplish what you're after is to run your script with the loop within a wrapper like the timeout command from the GNU Coreutils package. root@coraid-sp:~# timeout --help Usage: timeout [OPTION] DURATION COMMAND [ARG]... or: timeout [OPTION] Start COMMAND, and kill it if still running ...


8

I'm assuming you're using GRUB2 as your bootloader. You can disable the timeout by opening the file /etc/default/grub and changing the value of GRUB_TIMEOUT: GRUB_TIMEOUT=-1 will disable the timeout feature. See here for more information and settings.


8

With zsh, you could do: zmodload zsh/system coproc your-command while :; do sysread -t 10 -o 1 <&p && continue if (( $? == 4 )); then echo "Timeout" >&2 kill $! fi break done The idea being to use the -t option of sysread to read from your-command output with a timeout. Note that it makes your-command's output a pipe....


7

You can use traceroute for this, with the options -T for TCP and -p 22 to specify the SSH port. When using these options, you need to run traceroute as root: sudo traceroute -p 22 -T sshserver.example.com


7

The first answer is correct, but I've discovered how these timeouts work, so you could observe and test them (don't forget to block the port!). There are 4 most interesting kernel parameters that deal with TCP timeouts: /proc/sys/net/ipv4/tcp_keepalive_time /proc/sys/net/ipv4/tcp_keepalive_intvl /proc/sys/net/ipv4/tcp_keepalive_probes /proc/sys/net/ipv4/...


7

Use the timeout command, e.g. time 10s myscript. man timeout TIMEOUT(1) User Commands TIMEOUT(1) NAME timeout - run a command with a time limit


6

me=$$ (sleep 2; kill $me >/dev/null 2>&1) & nuker=$! # do whatever kill $nuker >/dev/null 2>&1 You're already trapping 15 (the numeric version of SIGTERM, which is what kill sends unless told otherwise), so you should already be good to go. That said, if you are looking at pre-POSIX, be aware that shell functions may not exist ...


6

From man ping: -w deadline Specify a timeout, in seconds, before ping exits regardless of how many packets have been sent or received. In this case ping does not stop after count packet are sent, it waits either for deadline expire or until count probes are answered or for some error notification from network. -W timeout ...


6

With bash: { (./slowprocess.sh >&3 3>&-; echo "$?") | if TMOUT=3 read status; then echo "Cool it completed with status $status, do stuff..." else echo "It didn't complete, do something else..." fi } 3>&1 Alternatively, if you want to use timeout (here assuming GNU timeout): timeout --foreground 3 sh -c './...


6

You should not have to do anything special, SSH does not terminate a connection because of inactivity. So there is no inactivity period defined within SSH. However one of the devices on the network route between you and your server might lose the route and for that activity from one side usually is enough, but not always (there are "arrival confirmation ...


5

Answered. This was the line: PID file /run/named/named.pid not readable (yet?) after start. The (yet?) threw me. I thought the message was being thrown because it was trying to read the PID file before it was written out by named and since I didn't see an error after that, I figured it eventually read it successfully. Silly me for reading English. In ...


5

Your assumption about it being used to mitigate brute force attacks is correct. In Linux, this is handled by the pam_faildelay module. There is a way to shorten the delay, but it is likely OS-specific. In Linux, the /etc/pam.d/login file contains the policy used for login(1). Here is an example line from a default debian install: # Enforce a minimal delay ...


5

The MPTSCSIH-Driver Release Notes from LSI look interesting. Major Changes For Version 2.06.75.00-1 Release Date: 12/10/2007 General Changes Functionality • Task Aborts for commands to a Volume are returned as FAILED and not sent to FW. Which version is your driver? (modinfo mptscsih) Use this link for Seagate Firmware information about your ...


5

Have a look at this Opensuse forum thread. It reveals that it's an issue with systemd's default unit timeout and not respecting the timeout setting in crypttab. It also provides a workaround -- letting the initrd take care of it, with an /etc/crypttab entry like this (i.e. adding the initrd) cr_sdb3 /dev/disk/by-id/ata-SHORTENED-part3 none ...


5

BASH FAQ entry #68: "How do I run a command, and have it abort (timeout) after N seconds?" FIRST check whether the command you're running can be told to timeout directly. The methods described here are "hacky" workarounds to force a command to terminate after a certain time has elapsed. Configuring your command properly is always preferable to the ...


5

On automatic configuration of IPv6 addresses Currently, IPv6 automatic configuration (in general) always relies on router discovery based on exchanges of ICMPv6 packets. The basic idea is to get the information about the network from the router to the client. Once the client receives the router advertisement with the information, it will also learn whether ...


5

I had a similar problem and was scratching my head over the lack of Google results (after ending up at this page a few times), so I decided to just read up on how systemd works here. Eventually I figured out that networking is actually a SysV init script (/etc/init.d/networking), which is converted to a systemd service at runtime (/run/systemd/generator....


5

If timeout times out, it exits with status 124; you can check this to determine whether the script timed out or not.


4

Assuming your remote server has a POSIX-compliant shell, the following should work: ssh ...options... 'command & pid=$!; sleep 20; kill $pid' Indeed the POSIX standard states about $!: Expands to the decimal process ID of the most recent background command (see Lists) executed from the current shell. (For example, background commands executed ...


4

are you using bash? or some other sh? read -t is a kshism (also supported by bash and zsh but not standard) It works in bash, but not in dash: $ bash -c 'echo foo | while read -t 3 xxxx ; do echo $xxxx ; done' foo $ dash -c 'echo foo | while read -t 3 xxxx ; do echo $xxxx ; done' dash: 1: read: Illegal option -t


4

There is timelimit: /usr/bin/timelimit - effectively limit the absolute execution time of a process Options: -p If the child process is terminated by a signal, timelimit propagates this condition, i.e. sends the same signal to itself. This allows the program executing timelimit to determine whether the child process was ...


4

Add this to the start of your .bash_profile ? if [ ! -z "$TMOUT" ]; then env -i bash --init-file ~/.bash_profile fi Beware the wrath of the sysadmins if you leave a gazillion old sessions running as a result of defeating their timeout rulings.



Only top voted, non community-wiki answers of a minimum length are eligible