Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mountainfield/bash-timeout
timeout function written by Bash
https://github.com/mountainfield/bash-timeout
bash shell shell-script timeout
Last synced: 9 days ago
JSON representation
timeout function written by Bash
- Host: GitHub
- URL: https://github.com/mountainfield/bash-timeout
- Owner: MountainField
- License: mit
- Created: 2018-06-13T04:42:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-06-23T07:25:23.000Z (over 6 years ago)
- Last Synced: 2024-10-14T00:36:24.980Z (about 1 month ago)
- Topics: bash, shell, shell-script, timeout
- Language: Shell
- Size: 15.6 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: docs/CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Bash Timeout
============[bash-timeout](https://github.com/nogayama/bash-timeout) is a command and also a bash function in order to terminate the target command if the target command does not finish within the duration specified beforehand.
The input via either redirection ( < FILE ) or pipe ( | ) are transferred to the target command transparently.
The exit status of the target command is retained if the target command finishes within the duration.The [timeout](https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html) in GNU coreutils is a similar command which has the timeout capability.
In shell script, bash-timeout make the script simpler than GNU timeout.
See [comparison.md](docs/comparison.md) for more details.Installing
----------- via pip
$ pip install bash-timeoutUsage
------ Use as a linux/unix command
```bash
$ bash-timeout 10s sleep 20s
```- Use as a bash function
```bash
source bash-timeout
timeout 10s sleep 20s
```- An example in bash script
```bash
source bash-timeout
function very_expensive_task() {
...
}
if timeout 10s very_expensive_task ; then
echo "successfully done"
else
echo "the task failed or timed out"
fi
```Characteristics
---------------1. Status code
1. Return error code if time out```bash
$ bash-timeout 10s sleep 20s
$ echo $? #=> 1 or more
```2. Retain the target command status code if the target command finishes within the duration
1. Normal exit
```bash
$ bash-timeout 10s ls /bin
$ echo $? #=> 0
```2. Exit with error
```bash
$ ls /FOOBAR
$ echo $? #=> 2
```
```bash
$ bash-timeout 10s ls /FOOBAR
$ echo $? #=> 2
```2. Input and Output
- Retain output
```bash
$ echo abc #=> abc
``````bash
$ bash-timeout 10s echo abc #=> abc
```- Retain input via pipe
```bash
$ echo abc | cat #=> abc
```
```bash
$ echo abc | bash-timeout 10s cat #=> abc
```- Retain input via redirection
```bash
$ echo abc > abc.txt
$ cat < abc.txt #=> abc
$ < abc.txt cat #=> abc
```
```bash
$ bash-timeout 10s cat < abc.txt #=> abc
$ bash-timeout < abc.txt 10s cat #=> abc
$ < abc.txt bash-timeout 10s cat #=> abc
```Author
------* **Takahide Nogayama** - [Nogayama](https://github.com/nogayama)
License
-------This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details
## Contributing
Please read [CONTRIBUTING.md](docs/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
Acknowledgments
---------------We express our sincere thanks to Scott Trent for reviewing documents.