Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [exit-code]

The tag has no usage guidance.

0
votes
3answers
76 views

Remote Command executed via ssh does not return proper return code. Return error code is always “0”, even condition failed

I am not getting proper exit return code during execution of remote script on a Linux machine. This script is intended for checking whether a user exists or not. My Script is below :- #!/bin/bash ...
0
votes
0answers
47 views

Is it possible to “coax” arbitrary core *nix utilities into returning a non-zero exit status even when successful?

I am running bash scripts and executing bash commands on remote systems using Connectwise Automate (formerly LabTech). These systems are both Linux and MacOS. Connectwise Automate (CWA) has some ...
1
vote
0answers
44 views

What does it mean when Duplicity exits with exit status 23? [closed]

I'm running Duplicity for backup of my desktop to a remote storage. Everything has been working fine, but now I see in my log that Duplicity has been exiting with exit status 23 for a couple of runs. ...
1
vote
1answer
21 views

Tool to run a command until exit status is 0

Is there a tool that can accept a command and run it over and over until exit status is 0? I could probably check for value of $? in a loop but I wonder if there's a standard program for this
10
votes
5answers
2k views

Capture exit code of exit command

I have this in a bash script: exit 3; exit_code="$?" if [[ "$exit_code" != "0" ]]; then echo -e "${r2g_magenta}Your r2g process is exiting with code $exit_code.${r2g_no_color}"; exit "$...
0
votes
2answers
53 views

how to know who is fail when doing ssh with test

Let's say I want to do some test VIA ssh example ssh 18.23.24.2 2>/dev/null "smartctl -a /dev/sdb -q silent" echo $? 1 in that case we get exit code 1 How to know if the problem is about ssh ...
0
votes
2answers
83 views

BASH: how can I save the exit code in PS1 in order to use it later in PS1?

I am attempting to customize my PS1, in the following way (I have removed the colours): PS1='\u@\h:\w$(git_branch)$(useExitCode)\$ ' where git_branch() { git branch 2> /dev/null | sed -e '/^[...
2
votes
4answers
369 views

What exit modes exist in shell-scripting in general and in Bash in particular?

I know that in shell-scripting an "exit" usually means voluntarily or at least successfully terminating a session (or a process within a session) and that there are several different exit modes; the ...
7
votes
3answers
125 views

Is there a way to get an process exit status after many more commands have been issued in linux?

If I have a lot of commands I've issued and I want the exit status of a process that exited say 100 commands ago. Is there a struct, file location, or variable in linux I can access all of exited ...
1
vote
0answers
43 views

Waiting for async console (message queue) output after invoking a command [closed]

I have to work with a command (lets call it update) which somehow prints its output asynchronously to the terminal (mq_timedsend). The output is not recognized as the commands output and therefore the ...
1
vote
1answer
116 views

Redirect YAD results into file AND still give exit codes from buttons to STDOUT

I have 2 custom buttons in my yad --form. The user input aka results get redirected into a .txt file for later use. Thats working fine. But it seems like the exit code is not given to STDOUT anymore, ...
1
vote
1answer
78 views

tput command doesn't work in if statement

I'm trying to use the tput command in a bash script if statement but for some reason it's behaving unexpectedly. When running the command and then checking the exit code only in the if statement ...
-1
votes
4answers
45 views

Is there a ping-like program that will return false when a packet is lost?

I'm trying to diagnose network instability on my home LAN -- I'm losing connectivity between my router and my cable modem. In my shell script, I'd like to ping the first ip address past the modem, and ...
0
votes
2answers
57 views

How do I make this script output: “Error connecting to Mom via SSH” when connection is down?

Intention I am in the middle of writing a little shell script (POSIX, except for the system_beep()). The script, which runs in Cygwin, should find out, if my mother's laptop is closed or not and ...
0
votes
1answer
233 views

What exit code integer grep returns when it doesn't match a string?

What exit code integer grep returns when it doesn't match a string? I know it returns 0 when it does match and I assume it returns 1 when it doesn't. Is that correct?
1
vote
2answers
691 views

Cron jobs monitoring using exit code

I want to monitoring cron jobs using shell script. But if I use variable contain exit code of last command I have "0" always. I think it's because I run this script after cron job and "exit code" ...
1
vote
1answer
557 views

The meaning of [ $? == 1 ] && return 0

I need to understand this command: [ $? == 1 ] && return 0
20
votes
5answers
3k views

What does typing a single exclamation mark do in Bash?

Bash uses exclamation marks for history expansions, as explained in the answers to this question (e.g. sudo !! runs the previous command-line with sudo). However, I can't find anywhere that explains ...
1
vote
1answer
256 views

How can I generate my desired exit code on shell commands or one-line scripts?

I would like to generate some exit code, say 20. But if I do on shell: $ exit 20 the shell is closed (X-Windows case) or I am logged out (text console case). Of course, inside .sh scripts, this ...
1
vote
2answers
142 views

get pppd exit code - how?

I'm designing some reporting system on Raspberry Pi system which connects to world thru 3G usb modem controlled by pppd. 99,999% of time connection works ok, but sometimes it drops and further ...
0
votes
1answer
539 views

How can I run the same command multiple times in series and capture all exit codes?

I am running an end-to-end test suite that's quite flakey, and I'd like a way to determine which tests are the flakiest. The easiest approach it seems would be to run tests 100s of times and return a ...
0
votes
1answer
108 views

Print variable inside loop

1. Summary I want to print variables from loop. If I place echo $i after command from loop:     Travis CI build passed. elif I place echo $i before command from loop:     I get exit code 1. I ...
8
votes
3answers
2k views

How can one extract the exit code of a command? [duplicate]

How can one extract the exit code of a command and use it in a condition? For example look at the following script: i=4 if [[ $i -eq 4 && $(command) -eq 0 ]] then echo "OK" ...
3
votes
4answers
3k views

Bash: Elegant way to set status? [closed]

true && echo foo will print foo. false && echo foo will not print foo. bash -c "exit $a" && echo foo will print foo depending on $a. Is there a more elegant way to write the ...
32
votes
4answers
9k views

What is the min and max values of exit codes in Linux?

What is the min and max values of the following exit codes in Linux: The exit code returned from a binary executable (for example: a C program). The exit code returned from a bash script (when ...
3
votes
2answers
846 views

What is the correct way of dealing with exit code of the last command?

I am currently doing this in a POSIX shell script: success=false pv --wait "$input_filename" | openssl enc -aes-256-cbc -d -salt -out "$output_filename" && success=true if [ "$success" = "...
0
votes
1answer
52 views

Perl: Error code returned to open3 after killed program

This program shows which error is returned to open3 when running either sleep 3 or true;sleep 3 and sleep is killed: #!/bin/bash ...
2
votes
2answers
90 views

if statement based on a command

I found this way to do if commands: $if echo test | grep st ; then echo yes ; fi ; echo $? test yes 0 Looks good. Let's try a non-match: $if echo test | grep 123 ; then echo yes ; fi ; echo $? 0 ...
1
vote
2answers
1k views

Why do high exit codes on Linux shells (>= 256) not work as expected?

I discovered a strange behaviour (reproducible with zsh and bash on my system): $ # here everything is still normal $ bash -c 'exit 1';echo $? 1 $ bash -c 'exit 255';echo $? 255 $ zsh -c 'exit 255';...
2
votes
2answers
985 views

How to get the exit code of commands started by find?

I am using "find" in a Travis-CI to check a particular file type with a program. (To be exact, it is a shellcheck check.) However, when using find the exit codes of the command(s)/subshells executed ...
1
vote
1answer
53 views

New prompt line not automatically put to command line upon exit code

When submitting jobs, I'm getting Exit codes returned, but I have to hit the return key for them to be printed to the log. 1. prompt_line/location sas query.sas & 2. [1] 66682 3. prompt_line/...
9
votes
7answers
2k views

Log exit code of command, similar to time command

using time sleep 1 yields: $ time sleep 1 real 0m1.005s user 0m0.001s sys 0m0.001s is there a command I can use to print the exit code of sleep or whatever command I want to run? ...