Tag Info

Hot answers tagged

44

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 ...


23

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 ;-))


21

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 ...


17

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 ...


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

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 ...


8

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 ...


7

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 ...


7

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 ...


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

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.


6

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


6

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 ...


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

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 ...


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

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 ...


4

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 ...


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.


3

There's also cratimeout by Martin Cracauer. # cf. http://www.cons.org/cracauer/software.html # usage: cratimeout timeout_in_msec cmd args cratimeout 5000 sleep 600 cratimeout 5000 tail -f /dev/null cratimeout 5000 sh -c 'while sleep 1; do date; done'


3

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 ...


3

This can be done with process groups (suggested here) and setsid to start new one: while true; do handle_input_with_timeout < <( setsid bash -c ' printf -- "-$$" > /tmp/saved_process_group.pid prog1 | prog2 | prog3 ') echo "Data stopped flowing. Trying again" kill -9 $(< /tmp/saved_process_group.pid ) ...


3

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 ...


3

timeout --signal=SIGKILL 10s timeout --kill-after=5 --signal=SIGINT 5s command


3

$ timeout 5s python write.py > out 2> err $ ls -l out err -rw-r--r-- 1 yeti yeti 10 Apr 6 08:12 err -rw-r--r-- 1 yeti yeti 0 Apr 6 08:12 out $ timeout 5s python -u write.py > out 2> err $ ls -l out err -rw-r--r-- 1 yeti yeti 10 Apr 6 08:13 err -rw-r--r-- 1 yeti yeti 10 Apr 6 08:13 out $ cmp err out && echo same same $ cat out 0 1 2 ...


3

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


3

In the terminal type mate-screensaver-preferences &, or from the Control Panel, select Screensaver - then deselect Lock screen when screensaver is active. You can find timeout settings there, too.



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