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-status]

Use this tag If your question revolves around determining or utilizing the exit status (return code) of a command. Common syntax involves the $? variable and the && and || symbols.

3
votes
2answers
239 views

Why can't I get pgrep output right to variable on bash script?

I'm trying to make a script to either quit compton if it's running or start it if it's not running. I've read from man that it should exit 1 if process is found, so I've tried to make a script that ...
0
votes
2answers
63 views

What is Linux exit status and list of all status

I'm trying to learn Linux bash scripting and I'm read through the articles in the http://tldp.org sites I saw some kind log clearing scripting I notice that something is used for as an exit status. I ...
0
votes
0answers
23 views

C++ script on Spark Cluster throws exit status 132

I'm trying to run a c++ program on spark cluster by using the rdd.pipe() operation but the executors throw: java.lang.IllegalStateException: Subprocess exited with status 132. The spark jar runs ...
3
votes
2answers
410 views

Bash Script Function Return True-False

I want to query the function by returning the value. My codes are as follows; check(){ file=/root/Turkiye.txt local funkx=$1 while read line; do if [ "$line" == "$funkx" ] ...
4
votes
1answer
66 views

Display output of `time` only if command after `time` was successful

I want the output of the time command to be shown only if the command, which has been passed to time was successful. Something like this: ( time wget -pq --delete-after https://www.example.com ) 2>...
3
votes
1answer
102 views

Failed to activate systemd-timesyncd.service

I've scanned all forums and questions and found no working answer to my problem. The Network Time Synchronization service doesn't work. The timedatectl service seems to work just fine without it ...
0
votes
3answers
132 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
47 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. ...
0
votes
2answers
24 views

Repeat command execution attempts until status is not specific, preserve data

I have a case where a first few command execution attempts after daemon restart are returning 2 (followed by stderr messages), than everything works correctly. In order to bypass this bug I've come ...
2
votes
1answer
336 views

systemd status=127 for /usr/bin/install when trying to start MariaDB

I just upgraded my MariaDB installation to 10.2. When I now try to start the service, it tells me it failed an checking the status shows me this rather strange message: root@server # systemctl status ...
5
votes
3answers
328 views

bash script executed over ssh returns incorrect exit code 0

I am trying to automate a process which involves running scripts on various machines via ssh. It is vital to capture both output and the return code (for the detection of errors). Setting the exit ...
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
4
votes
2answers
136 views

How to run multiple processes and exit if any of them exits or fails

I am running multiple processes and want to exit with the appropriate exit code (this means error on failure, success otherwise) if any of them fails or exists. Additionally if any child process ...
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
62 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 ...
2
votes
1answer
164 views

ldd equivalent which fail when library not found

Assume I perform ldd /bin/ls with the pthread library removed. I obtain linux-vdso.so.1 (0x00007ffcc3563000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f87e5459000) libcap.so.2 => /...
0
votes
2answers
111 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 '/^[...
0
votes
2answers
983 views

ls error code 2

I was reading the man of ls and in the end it talks about the Exit status of ls. It says: Exit status: 0 if OK, 1 if minor problems (e.g., cannot access subdirectory), 2 if ...
2
votes
4answers
395 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 ...
0
votes
1answer
33 views

Allow automated script to incorporate git rebase

I have this in a script: set -e; base="remotes/origin/dev"; git checkout --no-track -b "$new_branch"; git rebase "$base"; on occasion, there are conflicts of course, and what happens is that git ...
7
votes
3answers
135 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
46 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
139 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, ...
0
votes
2answers
87 views

Using shell 'printf' where the format string is in a variable and doesn't have a fixed number of field placeholders?

I am writing a shell function which makes an external API call via cURL (the external API syntax isn't under my control). I've approached it like this (simplified): #!/bin/sh template_get_entry='...
1
vote
1answer
93 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
58 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 ...
2
votes
1answer
118 views

Command don't return expected value inside .zshrc

Trying to run: function which_terminal { return (ps -p$PPID | awk "'NR==2'" | cut -d "' '" -f 11) } inside .zshrc to get a varible with which terminal emulator is running so I can configure ...
0
votes
1answer
334 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?
2
votes
1answer
639 views

Checking to see if rsync was successful

Is it possible to check if an rsync is successful and potentially collect an error if its not? As I am using --link-dest, I think this may be harder to detect. I'm fairly new to bash, so any ...
1
vote
2answers
785 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" ...
2
votes
3answers
566 views

How to reverse error code in Makefile

I want to test if file contain a pattern (skipped jasmine tests that should make my build fail, when run from travis). I have code like this: skipped_tests: $(if $(shell grep -E 'iit|ddescribe' ...
1
vote
1answer
682 views

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

I need to understand this command: [ $? == 1 ] && return 0
1
vote
2answers
665 views

Execute command and store everything to variable in bash

In bash script I'm developing I'm trying to execute command and capture in variable(s): stdout stderr status code how to achieve that? The command is tar, if it is of any significance. I tried the ...
1
vote
2answers
36 views

Using the value of a variable as an exit code from a script

I can find plenty of information about how to assign the exit code of a script to av variable, but I want to do the opposite: use the value of a variable (defined within a script) as the exit code of ...
7
votes
3answers
1k views

Why does the exit status differ when running `systemctl start; systemctl is-active` and `systemctl is-active` separately?

The following sequence gives me the return value of the first command, not the 2nd as I would have expected (no matter if I run the 1st command in a subshell): sudo systemctl start x; sudo systemctl ...
0
votes
1answer
640 views

Return value error in bash scripts

I have bash script like this: rm ~/sqoop/"$TABLE"/* rmdir ~/sqoop/"$TABLE" return $? After execution this script it returns a value to next process but even though the script run successfully and ...
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
65 views

Tracking child processes sequentially

I'm running few commands on a remote server, by sshpass. gnome-terminal --maximize --tab --title='aTask' -e "sshpass -p "afsd@#$5u89f" ssh root@192.168.0.125 'command1 && command2'" \ ...
0
votes
2answers
972 views

How to check for command exit code inside if statement

I'm trying to return a 0 exit code if a command exit with the a code 143 (timeout, from the "timeout command"), 1 otherwise. Due to external constraint (CI script), I have to start the command and do ...
1
vote
1answer
283 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
162 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
563 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
111 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 ...
1
vote
1answer
359 views

apt-get update failure returns 0 error code [duplicate]

When we run apt-get update and if it fails, a non zero error code should be returned, but in my case its still 0. See below: root@ubuntu-base:/home/user# apt-get update Err http://security.ubuntu.com ...
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 ...
2
votes
3answers
488 views

How to assign the success/fail status of a function to a variable in Bash?

I know that a way to do it is : # run a command here, like [[ $A == *"ABC"* ]] result=$? if (( result == 0 )) then result=true else result=false fi Then I can do : if $result then ... Is there ...