The tag has no usage guidance.

learn more… | top users | synonyms

0
votes
1answer
22 views

Stopping infinit loop from php script run in linux terminal

I am currently following a tutorial that teaches how to create a queue in php. An infinite loop was created in a php script. I simplified the code in order to focus on the question at hand: while(1) {...
0
votes
0answers
9 views

Use inotifywait to run command but only if inotifywait exits with status 0 [duplicate]

this is probably trivial. Normally I use the below to trigger a command on file event: inotifywait --event close /dir/file && my_command But will this run my_command even if inotifywait ...
2
votes
4answers
52 views

How to catch and handle nonzero exit status within a Bash function?

Say I have the following (pointless) Bash function: myfunc() { ls failfailfail uptime } I run it as follows: myfunc || echo "Something is wrong." What I want to happen is ls runs (as ...
2
votes
1answer
43 views

How do I check for the existence of a process without a failed exit code being returned?

I’m using Amazon Linux. I want to start a process provided one isn’t running already. This is a bash script I embed within a Jenkins Maven job. So I have pids=$(pidof /usr/bin/Xvfb) if [ ! -n "$...
0
votes
0answers
19 views

check if a variable contains letters and exit if true [duplicate]

I am using the line below to verify that an argument do not have a letter. If it have, the script will exit. Can you help me on how I can exit the script if the argument have a letter? echo $1 | ...
1
vote
1answer
44 views

Duration of /proc/pid/stat

I have a process that starts a child process and when the child exits, scans /proc/<pid>/stat to gather some information about the CPU and memory the child used. However I am worried that I am ...
3
votes
3answers
74 views

When interrupting a process, does a memory leak occur?

Lets say I created a program in c/c++, where I manually allocated some variables. Then while running the program, I send an interrupt signal (Ctrl-C). Are those variables freed from memory, or will ...
0
votes
0answers
66 views

Custom interrupt handler for bash scripts [duplicate]

I'm writing a script that needs to keep track of all backgrounded processes it launches: index=0 for i in `ls $TOPOLOGY_FILE_PREFIX*` do if [ ! -z "$11" ]; then ./noc_sim.sh -...
0
votes
1answer
18 views

Less quit behavior

I'm not sure how to describe this but I'll try by comparing it to vi. When I open vi, do something, and then exit vi it brings me back to the terminal where I can see all of the commands I had ...
0
votes
1answer
36 views

My if bash script always execute the break

I`m making a script to rename files in a folder. The new name for the files is in a config file. I have to be sure that the file I want to rename corresponds to the current one in the config file. My ...
3
votes
1answer
116 views

Why does the exit code of a script appear to have a different value than what is returned?

I have a script (run-docker-container.sh) that calls another script (create-docker-container.sh). create-docker-container executes a curl script against the docker remote api and returns the http code ...
1
vote
3answers
105 views

Where is `exit` defined?

Suppose I want a bash command to do something extra. As a simple example, imagine I just want it to echo "123" before running. One simply way to do this would be to alias the command. Since we ...
0
votes
2answers
30 views

Why is the exit status always 0 at the start of a script?

I have a script like this, named judge: #!/bin/bash echo "last exit status is $?" It always outputs "last exit status is 0". Eg: ls -l; judge # correctly reports 0 ls -z; judge # incorrectly ...
0
votes
2answers
52 views

exit code of the command **before** last? [duplicate]

I'm running a script within a script, release.sh and caller.sh (caller.sh calls release.sh). Both are bash. release.sh contains a bunch of conditions with 'exit 1' for errors. caller.sh contains a ...
0
votes
1answer
24 views

Function does not get called and script exits

So i got the function RM_OBJ_P which gets called from the menu page PAGE_RM. This is working, you can enter all the funky filenames you know and if they are in the database, the output gets printed ...
4
votes
1answer
97 views

bash does not exit on abnormal exit of child process due to signal

I try really hard to understand what I am doing wrong and why? I have a launch.sh script which launches process.sh. launch.sh #!/bin/bash while true; do ./process.sh done process.sh #!/bin/...
0
votes
4answers
183 views

bash : multiple command on one line with different exit code

I run a bash command from a c++ code using the system function provided in cstdlib. My question is not about the c++ implementation, but the one thing that is relevant to my question, is that I have ...
1
vote
3answers
173 views

How to force ssh connection to exit at end of script

I have a script which is composed of two parts. part1 creates an ssh connection, part2 runs a script (about 800 lines and counting so far). part1: ssh $target_server "bash -s" < $target_script ...
2
votes
3answers
180 views

How to wait for all spawned and backgrounded processes to finish in bash script

I've looked and looked and can't find a working solution to a bash script I'm trying to create to shut a process down and wait for it and spawned processes to finish. I'm still learning a lot of Linux....
1
vote
1answer
32 views

Retrieve data from mem cache

Newbie to Linux. My application writes to a log file and for some reason it stopped writing to that file suddenly. We have restarted the application to fix this glitch. Is it possible to retrieve the ...
1
vote
2answers
136 views

How to stop bash scripts from exit ing the window altogether

When I write bash script and I have exit;; or exit 0;; the script not only exits but the window (or pane in the case of tmux panes) exits completely (goes away). e.g. while true; do read -p ...
0
votes
1answer
49 views

Idiomatic bash way to run optional action without side effects on exit code

This script will exit with test result which is not desired from callers perspective. How it should be implemented instead? #!/bin/bash test -n "" && echo "test passed"
12
votes
6answers
2k views

Using “reserved” codes for exit status of shell scripts

I recently came across this list of Exit Codes With Special Meanings from the Advanced Bash-Scripting Guide. They refer to these codes as being reserved and recommend that: According to the above ...
5
votes
2answers
519 views

Keep exit codes when trapping SIGINT and similar?

If I use trap like described e.g. on http://linuxcommand.org/wss0160.php#trap to catch ctrl-c (or similar) and cleanup before exiting then I am changing the exit code returned. Now this probably won'...
0
votes
1answer
197 views

Skip 'natural' exit in trap

How are you? My script looks like: trap "$(pwd)/dd-destroy.sh $l-env;$(pwd)/dd-drop.sh $l-db;exit" INT QUIT TERM EXIT ./dd-all.sh $l $l-db $l-env || exit 1 app_ip=$(./dd-status.sh ip $l-env|grep ...
2
votes
2answers
199 views

When does a process terminate in UNIX?

At which moment a process in Unix is terminated? Is it necessary a command such as exit(0) or return 0 to be written in a program to terminate a process? My question is provoked by the following code: ...
0
votes
1answer
106 views

What's wrong with exit command on my terminal?

I'm using Linux Mint 17.2 Cinnamon, and I'm a beginner, just switched over from Win10. Somehow, the exit command isn't working, could somebody help me out?
2
votes
3answers
105 views

Why does using pipe '|' terminate the second process, is there a way to prevent it?

Just to give some context, I'm trying to run this command echo "set hive.execution.engine=tez;" | hive hive terminates as soon as "set hive.execution.engine..." has been entered into the hive ...
1
vote
1answer
109 views

Awkward awk exit code

I'm writing some awk scripts for data validation. These are intended to be selected and invoked by another proces which needs to see the exit code from the awk script to determine if the content was ...
2
votes
1answer
356 views

What does exit code 130 mean for postgres command?

When attempting to start PostgreSQL server using the /usr/pgsql-9.2/bin/postgres command I get an exit value code of 130. However I could not find any documentation for the exit codes of this command....
0
votes
1answer
88 views

Bash exit from subcommand [duplicate]

I have a script with the following code: command_that_could_fail || (echo "command failed"; exit 1) However, the exit seems to just be exiting from the sub-command formed by the second part of the ...
4
votes
2answers
213 views

Run an app with a window manager behind in a separate X server

I want to launch an app in a separate X server. It needs a window manager behind it, though. I created a script #!/bin/sh x-window-manager & my-gui-app and launched it with xinit myscript....
2
votes
1answer
264 views

capture exit status from screen

I have a long-running command that I've been running in screen so as to be able to interact with it when it encounters bugs. But I'd also like to be able to start it via another shell script (which ...
3
votes
2answers
1k views

Call a script for another script, but don't exit the parent if the child calls exit

first.sh: #! /bin/ksh echo "prova" . ./second.sh echo "ho lanciato il secondo" . ./third.sh echo "ho lanciato il terzo" second.sh: echo "sono nel secondo script" dosomething1 exit $? If second....
1
vote
2answers
181 views

How do i have my script execute one more command after a previous command returns a non-zero value before it is aborted?

I have a shell script that calls on a Perl script to do some file processing. The Perl scripts exits with either a zero or one value. I have the Unix set -e command at the beginning of my script to ...
0
votes
2answers
443 views

breaking out of command loop but exit code not the reason?

I run the following: echo "while emacs;do echo $?;done;echo Exit code: $?;" | bash If I exit emacs through the menu or the close button, it prints exit code 0 and restarts. If I exit emacs through ...
4
votes
3answers
5k views

Exiting a shell script with nested loops

I have a shell script with nested loops and just found out that "exit" doesn't really exit the script, but only the current loop. Is there another way to completely exit the script on a certain error ...
1
vote
2answers
368 views

Shell script exit code and logging

I have got following simple shell script, in which I am trying to send STDERR & STDOUT to both screen and log it in a file(test.log). Also, while exiting I am trying to exit with appropriate exit ...
0
votes
2answers
251 views

Having trouble with basic if then statement

learning the basics of scripting and I have this line of code: #!/bin/sh if [ $# -ne 1] then echo "Please provide one directory to search" echo "Example usage: something.sh directory_name" ...
0
votes
1answer
402 views

How to terminate cat command within a shell script

I wrote a shell script that uses cat and tr commands to generate a file. My shell script looks like #!/bin/bash printf "generating random file > plaintext \n" cat -v | tr "a-z" "b-y" < ...
2
votes
3answers
2k views

Parent script continues when child exits with non-zero exit code [closed]

I have a script that calls another script. When the child script fails, I'd like the parent to fail as well. In the child script child_1.sh, I have something like this: if [ $SOME_BAD_CONDITION ] ; ...
6
votes
4answers
971 views

Why is it “while kill -0 $PID” and not “until kill -0 $PID”?

I may be being daft here, but if I want to do something while a process is running, why do I do: while kill -0 $PID do #... done instead of until kill -0 $PID do #... done ? kill -0 ...
0
votes
3answers
15k views

Bash ping script file for checking host availability

I am trying to write a bash script in a file that would, when run start pinging a host until it becomes available, when the host becomes reachable it runs a command and stops executing, i tried ...
1
vote
1answer
47 views

What is the most Unix-y way to handle stdout for a backup command that might fail?

I am writing a utility/script (in Python, as it happens) to run on Linux, which backs up data from a remote server, and outputs to stdout. At the moment, I run this script on the hour from cron, and ...
28
votes
2answers
6k views

Why does ( echo “”; exit 1) not exit the script?

I have a script, that does not exit when I want it to. An example script with the same error is: #!/bin/bash function bla() { return 1 } bla || ( echo '1' ; exit 1 ) echo '2' I would assume ...
1
vote
3answers
4k views

What return/exit values can I use in bash functions/scripts?

I want to know what return values we can use that will not be mistaken by for ex. SIGINT? ex.: $sleep 10 $#hit ctrl+c $echo $? 130 so I know I must not use anything like return 130 or exit 130 so ...
2
votes
1answer
733 views

YAD - Terminate Bash Script

I'm using YAD to create a Yes or No dialog box in a bash script: yad --image "dialog-question" --title "Alert" --button=gtk-yes:0 --button=gtk-no:1 --text "Are you sure you want to do this?" If I ...
5
votes
2answers
793 views

How do I look up exit codes for applications?

I'm having difficulty locating a comprehensive up-to-date list of error codes from Bash. e.g.: $ udevadm info /dev/sdx; echo Exit code $? Unknown device, --name=, --path=, or absolute path in /dev/ ...
1
vote
1answer
313 views

How do I get the exit code of a process, which runs through wine

I'm trying to run a Windows executable via wine. When I first try to run it never runs, but when I attempt to do it again, the program runs. I'd like to make a script to run the program, here's the ...
35
votes
4answers
5k views

Is there any UNIX variant on which a child process dies with its parent?

I have been studying the Linux kernel behaviour for quite some time now, and it's always been clear to me that: When a process dies, all its children are given back to the init process (PID 1) ...