The exit tag has no usage guidance.
1
vote
0answers
20 views
How to find status of init.d exit scripts which return 0 on failure?
It seems that many init.d scripts return 0 on failure, in spite of these recommendations. For example, in nginx, running directly:
/usr/sbin/nginx -t # returns 1 (with a bad config)
and ...
14
votes
4answers
2k views
How does the exit command work on a Unix terminal?
Could someone please explain how the exit command works in Unix terminal?
A search of man exit and which exit was not helpful and I have come across the following issue.
After installing add on ...
1
vote
1answer
48 views
Capture exit status code from ssh
#!/bin/bash
RET=0
export RET
{
ssh -q -t user@host <<EOF
echo "hello there "
exit 10
EOF
RET=$?
echo "Out is" $RET
} &
echo "RET is $RET"
################## End
I get RET 0
OUT is 10
How ...
1
vote
1answer
22 views
Checking if the last diff command had output
I have some commands in a file that are like
diff file1 file2
diff file3 file4
And if anything is output I want to print which command this happened in such as
diff file1 file2
if (there was ...
1
vote
2answers
64 views
Shell script exits early for unclear reasons
I'm using the following script to backup, using Borg Backup. But I'm running into an odd problem
Part of the script below does not execute. The script follows, then the output
SCRIPT:
#!/bin/bash ...
5
votes
3answers
66 views
How to get further information about the origin of an exit code?
Sometimes I need to maintain programs that invoke shell scripts which invokes other programs and scripts. Therefore, when the main shell script ends with exit code 126, it is a struggle to find out ...
1
vote
2answers
127 views
Exit code at the end of a bash script
I am confused about the meaning of the exit code in the end of a bash script:
I know that exit code 0 means that it finished successfully, and that there are many more exit codes numbers (127 if I'm ...
-1
votes
1answer
102 views
exit command behaves differently in Linux and HP-UX
I am working in HP-UX (B.11.23) to LINUX (Red Hat Enterprise Linux Server release 6.5 - Santiago) migration project. There were several occurrences where HP-UX commands were not working properly in ...
0
votes
1answer
94 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
11 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
262 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
100 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
105 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
120 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
48 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
43 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
365 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
142 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
42 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
129 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
27 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
175 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/bash
...
0
votes
4answers
446 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
353 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
274 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
33 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 ...
2
votes
2answers
204 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
54 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"
13
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
986 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
367 views
Skip 'natural' exit in trap
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 docker-app|...
2
votes
2answers
420 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
151 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
130 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
152 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
491 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....
1
vote
1answer
149 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
249 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
390 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
4k 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.sh ...
1
vote
2answers
265 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
690 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 ...
5
votes
3answers
7k 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
486 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
387 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
561 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" < ...
3
votes
3answers
3k 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
1k 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 exits ...