Tag Info

Hot answers tagged

20

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


16

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


11

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


11

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


7

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


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

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


6

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


6

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


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

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

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.


4

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


4

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


4

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


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

You can use traceroute for this, with the optiopns -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


3

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


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

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


2

Have you tried changing your I/O schedulers? mccoy:/sys/block/sdb/queue # cat scheduler noop anticipatory deadline [cfq] mccoy:/sys/block/sdb/queue # echo noop > scheduler mccoy:/sys/block/sdb/queue # cat scheduler [noop] anticipatory deadline cfq The default is CFQ typically for most systems "currently." To compare I/O schedulers ...


2

I have solved the problem by buying a SAS2008 card. It still complains a little in the log, but it never blocks the disk I/O. Also I have tested it supports 4 TB SATA drives, whereas the LSI-SAS1068E only supports 2 TB. As I will be returning the LSI-SAS1068E to the seller, I will not be able to try out other suggestions. Therefore I close the question ...


2

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'


2

I think you want the timeout command, which is part of coreutils and should be available on your system To kill the command after 5 seconds, change to: timeout 5 iqdl -n $REPOSITORY_NAME.$cs ... If you don't have coreutils, you can download, build and install it from here: http://www.gnu.org/software/coreutils/ See also: ...


2

You can set generic TCP keepalives, I think there is a kernel setting for that. But they're usually much less frequent (hours). There is a TCP Keepalive HOWTO which appears to have details. Alternatively, why not just tunnel the MySQL connection over SSH, then you can use SSH keepalives? $ ssh -L1234:127.0.0.1:3306 -o ServerAliveInterval=300 ...


2

MySQL CLI client defaults with auto-connect, if a connection is lost during a session. Documentation: MySQL Tips & Controlling Automatic Reconnection Behavior. The real solutions would be to work with the powers-that-be, and figure out a solution that works for development team-members. Naturally that would take some time, so a temporary solution ...


2

I've found something a little better, than timeout: timelimit. It has several advantages; one is that user can manually abort execution by pressing "Ctrl+C". The timelimit program is available in Debian repository.


2

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


2

You can tune cpu time and other things with ulimit, for cpu time particularly: $ ulimit -t 60 # limit to 60 seconds $ program



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