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.

0
votes
2answers
44 views

Exit status of last command using PROMPT_COMMAND

I want to save the exit status of the last ran command (in a file, in a variable, it doesn't really matter), but this must be done automatically in an interactive shell, manually running something ...
4
votes
4answers
337 views

Bash - Execute two commands and get exit status 1 if first fails

In the case below, the report command must always be executed but I need to get an exit status 1 if the test command fails: test;report echo $? 0 How can I do it in a single bash line without ...
1
vote
1answer
57 views

Exit status of chained commands

I want to run a potentially invalid command in a variable cmd. I can't afford to have it just fail me and retrieve the exit status. What I can try to do is pipe it to : and then I'll have a successful ...
0
votes
3answers
63 views

Handle specific error in bash

As a part of my script, I want to publish package to nuget feed: dotnet nuget push package.1.2.3.nupkg --source "mysource" --api-key "mykey" The command may print error: 409 already contains version ...
0
votes
2answers
56 views

Why echo$?' returns 0 even though 1 is expected? [closed]

For the following program, I get 0 for echo$? even though I expect 1. int main() { return 1; }
0
votes
1answer
56 views

exit status from rsync command

When I am executing rysnc command the exit status is 0, even though the command throws an error (code 23). I want to use the exit status code to terminate the script when there are no files found but ...
4
votes
1answer
100 views

How to make `trap` know if the EXIT is after successful program finish or because of premature as an error or something

PROBLEM: I have a shell program that I have been writing but I can't find out how to make sure that trap is trapping for cleanup at the end or because of a error in some command, it cleans up either ...
0
votes
0answers
36 views

How to enter and leave a man page in a script

I want to run a script that enters a man page and leaves it. Something like (in pseudo-code) $ man man q How can I do such a thing? Preferably the exit code will be 0. More generally how do I do ...
26
votes
1answer
981 views

Finding files for which a command fails

I would like to recursively find all the files for which a script which accepts a file as an argument returns a non-zero value. Any idea how to do this using 'find' or a similar tool?
3
votes
2answers
351 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
152 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
27 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
868 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
69 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>...
4
votes
1answer
416 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 ...
1
vote
3answers
430 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
51 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
94 views

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

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
25 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 ...
3
votes
2answers
713 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
449 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
24 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
255 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
79 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
244 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
156 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
2k 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
432 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
42 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
161 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
58 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
174 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
114 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
135 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
63 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
144 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
517 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
805 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
968 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" ...
3
votes
3answers
716 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
881 views

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

I need to understand this command: [ $? == 1 ] && return 0
2
votes
2answers
1k 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
40 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
2k 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
840 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
71 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
1k 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 ...