Tag Info

Hot answers tagged

13

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

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


6

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


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


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

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


3

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


3

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


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

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


3

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


2

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


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

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

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


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


1

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


1

I was able to modify the solution in http://h30499.www3.hp.com/t5/System-Administration/Capturing-hung-command-in-a-script/td-p/5662103 to match my requirement. I tested and this is perfect for me. I appreciate all your help. #!/bin/ksh WAITTIME=5 # run the idql command in the background, discarding any output idql -n $REPOSITORY_NAME -Udmadmin -P"" ...


1

Launch a watchdog process from within your script to kill off its parent if it runs too long. Example: # watchdog process mainpid=$$ (sleep 5; kill $mainpid) & watchdogpid=$! # rest of script while : do ...stuff... done kill $watchdogpid This script will be terminated by the watchdog after five seconds.


1

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


1

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


1

A pure bash solution using only near-universally available system commands: timeout() { if (( $# < 3 )); then printf '%s\n' 'Usage: timeout sigterm-seconds sigkill-seconds command [arg ...]' return 1 fi "${@:3}" & pid=$! sleep "$1" if ps "${pid}" >/dev/null 2>&1; then kill -TERM "${pid}" ...


1

On a sufficiently recent Linux system (more precisely, with GNU coreutils ≥8.5), it's as simple as timeout 2m myprogram With only POSIX shell features, you can come close, but there is a small race condition if the timeout occurs (in theory, the PID of the second background process could be reused just before kill $s is executed). myprogram ...


1

So succeeded with a "little" timeout script that checks the log file size to determine if the process is still working. Not pretty, but did help: #!/bin/sh TIMEOUT=$1 FILE=$2 PID=$3 if [ -z "$PID" ] then echo $0 timeout file pid echo " e.g. 60 /tmp/log 16325" exit fi echo "stalekill: timeout=$TIMEOUT file=$FILE pid=$PID" sleep 1 SIZE=0 ...


1

Although coretuils as of version 7.0 includes a timeout command you've mentioned some environments that won't have it. Fortunately pixelbeat.org has a timeout script written sh. I've used it before on several occasions and it works very well. http://www.pixelbeat.org/scripts/timeout (Note: The script below has been slightly modified from the one on ...



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