Linked Questions

70
votes
5answers
52k views

Run multiple commands and kill them as one in bash

I want to run multiple commands (processes) on a single shell. All of them have own continuous output and don't stop. Running them in the background breaks Ctrl-C. I would like to run them as a single ...
41
votes
5answers
124k views

How to introduce timeout for shell scripting?

I want to run a shell script that got a loop in it and it can go for ever which I do not want to happen. So I need to introduce a timeout for the whole script. How can I introduce a timeout for the ...
55
votes
1answer
23k views

Run a command for a specified time and then abort if time exceeds

I want know how I can run a command for a specified time say, one minute and if it doesn't complete execution then I should be able to stop it.
18
votes
6answers
4k views

Get the display width of a string of characters

What would be the closest to a portable way to get the display width (on a terminal at least (one that displays characters in the current locale with the correct width)) of a string of characters from ...
11
votes
3answers
8k views

Preventing propagation of SIGINT to Parent Process

Considering a scenario where a Parent program (could be a C++ program or a Shell Script) executes a Child shell script, when we hit Control+C (or whatever character is configured to be the INTR ...
6
votes
3answers
10k views

Automatically kill process if its runtime exceeds some predetermined value

I want to start a process from a shell script, allow it to interact with the user (so I cannot just background it, grab the PID, launch sleep followed by sanity checks and kill), but if it is still ...
10
votes
3answers
4k views

Detect how much of Unicode my terminal supports, even through screen

Here's the problem: I want to be able to discern if my terminal is capable of decent unicode or not, in order to use some characters or not, much like glances does, that sometimes uses colors and ...
17
votes
1answer
2k views

POSIX equivalent for GNU timeout?

The GNU coreutils timeout command is extremely handy for certain scripting situations, allowing for using the output of a command if it is quick to run, and skipping it if it would take too long. How ...
3
votes
3answers
2k views

Please help explain this bash output redirection

This script was posted as answer to a Question. And I'm trying to work out what's going on. result=$( { { ssh host app-status >&3 3>&-; echo "$?" } | { until read -...
2
votes
2answers
2k views

Timeout doesn't occur when reading from fifo using `read`

Look at this code: while read -t 3 line; do echo ${line} done < /opt/data.log data.log is a fifo. One process is writing to this, and this code should be reading it to show to the user. But I ...
2
votes
3answers
3k views

Timeout `idql` command in ksh

Below is my code snippet. idql -n $REPOSITORY_NAME.$cs -Udmadmin -P"" -R$DM_SCRIPTS/test.api > /dev/null 2>&1 if [ $? != 0 ]; then echo " \c" echo "ERROR: Cannot connect ...
2
votes
2answers
3k views

Time limit for bash script

I have bash script and I would like to set time limit for it. For example if scripts runs longer than 50s, exit with 0. It should be done inside script, I can not change the command how script is ...
0
votes
2answers
1k views

How to get the results from “\033[6n” in an sh script

It took me 10 hours of searching the net, and testing techniques to get the results that worked on any shell (#!/bin/sh). In BASH this is relatively simple, because read can be told how many ...
5
votes
1answer
1k views

How to move a process from one process group to another, and how to list the processes in each process group?

Based on what I have learned so far, a terminal has only one session, and a session has one or more process groups, and a process group has one or more processes. The following image illustrates this: ...
5
votes
1answer
296 views

How to redirect a command's `stdin` as well as `stdout` to the output

Suppose I have the Python script: #!/usr/bin/env python input('Y/n: ') print('Next line') After I press Y, I want both the terminal and my output.txt containing: Y/n: Y Next line Running the ...

15 30 50 per page