Questions tagged [trap]

The tag has no usage guidance.

27 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
1answer
201 views

Remote script cleaning up

I run a remote script using ssh: local script: local_command ssh -p 222 user@server 'sh -s' < ./remote_run.sh remote script: some_command & sleep 10000 trap 'echo exiting' SIGINT SIGTERM ...
2
votes
0answers
121 views

Disabling “some” traps temporarily, and re-enabling them

I need to disable some(not all) of the traps temporarily in my function and then re-activate them. But I get an unexpected behaviour(I'm pretty new to traps and signals though) when I'm doing it: ...
2
votes
0answers
44 views

How to trigger a command after named pipe closes?

How can I execute some command after the named pipe has been readout in other end. I was trying to use trap. But nothing happens. My script is something like below. #!/bin/sh cleanup() { echo "...
2
votes
0answers
106 views

DEBUG trap statement in ksh93 not executed after first run if it contains exit or return statements

I was trying to write a simple function that checks if a config file is "sanitized" and safe for sourcing or not. I seemingly got it to work in bash, and in ksh (Version ABIJM 93v- 2014-06-25) in the ...
2
votes
0answers
420 views

trapping signals without interfering with other signals

When trapping a signal in a shell script, the trap commands are not executed until the current command finishes. For example, consider the following shell script: #!/bin/bash trap 'echo "SIGTERM ...
2
votes
1answer
711 views

Trap does not catch SIGTERM in child script

I have two scripts. First one is basically wrapper that calls subscript and sets timeout. #!/bin/bash # wrapper_script timeout --signal=SIGTERM 50 main_script.sh And if execution of main_script.sh ...
2
votes
0answers
43 views

`trap n condition` syntax

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#trap : trap n [condition...] trap [action condition...] If the first operand is an unsigned decimal integer, the shell ...
2
votes
0answers
1k views

bash parent and child signal handling

Quick summary: parent and child in a loop, each can either trap or not trap signals. I don't understand why, if the child traps and the parent doesn't, the parent is not terminated. The detail: I ...
2
votes
0answers
108 views

How can set value for mteHotContextName when using monitor process in SNMP

I'm using RHEL 5, I tried to find some way to set value for set value of mteHotContextName or mteHotTargetName of DISMAN-EVENT-MIB but I can't find the answer. I searched in stacoverflow but nothing ...
2
votes
0answers
1k views

Catch the kill signal when a process is in S state [interruptible sleep]

This is the process group : (ps -ejH) xxxx xxxx xxxx ? 00:00:00 sshd yyyy yyyy yyyy ? 00:00:00 sshd 8713 8713 8713 pts/0 00:00:00 bash 1234 1234 1234 ? ...
2
votes
0answers
680 views

exit code of grep in trap where the script is launched by upstart service

Recently I encountered a problem in ubuntu upstart and trap in Bash shell. I use ubuntu 12.04. The upstart script(/etc/init/player.conf) is: start on (local-filesystems and runlevel [2345]) stop on ...
1
vote
0answers
253 views

'unbound variable' error when using function-level bash trap (trap … RETURN)

Consider this script that calls into a function that sets up a trap for the RETURN of that function: #!/usr/bin/env bash set -euo pipefail function f1() { local temp_file temp_file="$(mktemp)" ...
1
vote
1answer
485 views

lock file not removed when trap is inside an “if”

I put my trap inside an if, run the script, and after that second execution, it warns that lock file is held (ok). But when I kill -9 the running PID, the lockfile is not removed. When I move trap ...
1
vote
0answers
80 views

What determines a login shell's default trap handlers?

I have a linux box that when I login with ssh, both the keystroke Ctrl-C and manually sending SIGINT will directly terminates the session. λ> ssh root@rhel74 Last login: Sun Mar 18 21:08:02 2018 ...
1
vote
0answers
1k views

Restoring tty correctly with stty

I'm writing a bash script to read some user input (like a password request), and I'd like to capture the result and pass it through its stdout. (I'm working in a GNU/Linux environment, with recent ...
1
vote
1answer
484 views

Shell scripts connected with pipe: trap termination of one script

I have two shell scripts, one runs on a server and writes some files to a temporary directory. This directory is then sent as a tar archive to stdout. At the end (or when it gets interrupted), the ...
1
vote
0answers
751 views

Test/Simulate SNMP traps on disk failures

On my monitored system I configure SNMP to sent traps in the event that hardware failures occur. For example, I add the following (rather well-known) line to my snmpd.conf file: monitor -60 -o ...
1
vote
0answers
225 views

killing subprocesses and traps

I have the following two scripts which simulate some work: start.sh simply launches 2 (mpi) processes with script mpiproc.sh. start.sh #!/bin/bash function trap_with_arg() { func="$1" ; shift ...
1
vote
0answers
255 views

Redirect SNMP ports to router for use with openHAB SNMP binding

OpenHAB provides an interesting SNMP binding that would allow me (I think) to get network bandwidth use statistics that may be used in rules. Interesting as the may be, it seems that openHAB cannot ...
1
vote
2answers
240 views

Default function arguments (manually emitting bash psuedo-signals)

I'm looking for a solution that will automatically allow me to call a function with specific parameters in a certain situation. Here is the specific scenario: When an error occurs, I can set up my ...
0
votes
1answer
50 views

Proper way to trap in zsh script

I'm having trouble getting a trap function in a zsh shell-script to work without exiting the shell. I have a simple countdown timer that I want to be able to interrupt using Ctrl+C, and when I do I ...
0
votes
0answers
44 views

Bash Trap Handler Race Condition

I am playing with bash's trap feature. And the following script exhbits some kind of race condition. #! /bin/bash set -x trap sigusr1 USR1 ANCESTOR_PID=$$ function sigusr1 { num+=1 declare ...
0
votes
1answer
1k views

unable to launch any program: trap int3 ip error

I cannot launch any program in my desktop environment. I get these errors in dmesg: traps: terminator[3670] trap int3 ip:374dda71261 sp:388624bbec0 error:0 traps: pcmanfm[3685] trap int3 ip:...
0
votes
0answers
48 views

trap signal in bash initramfs fails to work

inside /init bash script executed by the kernel in initramfs.img i need to send a signal to drop me to a rescue shell, so i have trap "exec /bin/bash" SIGINT but ctrl+C isn't effective. First why ...
0
votes
0answers
255 views

trapping HUP/SIGHUP is not working in bash script

I have this bash script: https://gist.github.com/ORESoftware/06dbb26a48d2ddf48a5a2166834e0836 when I call ql_acquire_lock in a shell, if I can call mkdir on a directory, then I acquire that lock. ...
0
votes
1answer
149 views

Can I capture trap messages along with $LINE_NO?

I have a code like: trap 'error ${LINENO} ${BASH_COMMAND}' ERR I want to capture error message along with this. Is there any built-in variable for printing error message?
0
votes
0answers
479 views

spstack, ptrace stopped a process

My server is busy with sys CPU, so I used pstrace to trace it but no output, so I cancel the command inside putty, and then use pstack to trace it again, but no result return either and I closed the ...