The tag has no usage guidance.

learn more… | top users | synonyms

0
votes
4answers
60 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
110 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
48 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 ...
1
vote
1answer
30 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
47 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
37 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"
11
votes
6answers
969 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
184 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 ...
0
votes
1answer
87 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
95 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
65 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
79 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
85 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
210 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 ...
0
votes
1answer
48 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
168 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 ...
2
votes
1answer
145 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 ...
2
votes
2answers
452 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 ...
1
vote
2answers
110 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
209 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
2k 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
238 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
147 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
304 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" < ...
1
vote
3answers
1k 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
858 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
8k 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
43 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 ...
27
votes
2answers
4k 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
3k 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
611 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
564 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
238 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 ...
34
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) ...
2
votes
3answers
416 views

Should I embed a command in a conditional or test its return code?

It's a simple question of best pratices: Which should I use? Option 1 ping -c1 "$host" if [[ $? -eq 0 ]] ; then command else command fi Option 2 if ping -c1 "$host" ; then command ...
3
votes
2answers
266 views

exit a script if an ls line did not find any match

I am writing this script that have this line: ls -lrt /dir1/dir2/filename*.txt | tail -1 | awk '{print $9}' | read variable What I wanted is to exit the script (without using if-statement) if it ...
8
votes
4answers
3k views

New parent process when the parent process dies

In UNIX, when a parent process disappears, I thought that all child processes reset init as their parent. Is this not correct all the time? Are there any exceptions?
1
vote
3answers
1k views

Determining the exit status of the “return” built-in

I was reading about traps, but only return works for me in my shell script, so was wondering what status or code it returns, so what I tried is, #!/bin/bash seeOutput=`return` echo $seeOutput It's ...
1
vote
1answer
205 views

'script' session logging makes me exit twice

I'm using a solution described here to log my shell sessions, by adding this to the end of /etc/bash.bashrc: test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f ...
1
vote
1answer
91 views

Can Linux programs be sent a SIGXXX command they can respond to in the UI?

I am trying out the timeout command and would like to know if there is a kill signal that a GUI program, whether a graphics desktop or a terminal program will treat as the user terminating the program ...
2
votes
1answer
114 views

more command behavior

Someone can explain me about the more command? when I use it with || or with &&, it seems to have an exist status of true, even when the file is not found(Unlike the other commands). ...
1
vote
1answer
52 views

How do I obtain the kill signal / message / reason within a script?

I am using the following trap: trap OnExit EXIT And in my OnExit function I would like to capture all the info I can on what happened so I can write it to a log file. Id like to know who, why, how, ...
0
votes
2answers
5k views

Exit the bash function, not the terminal

I have a bash script as below which installs zookeeper but only if not installed already. ##zookeper installZook(){ ZOOK_VERSION="3.4.5" ZOOK_TOOL="zookeeper-${ZOOK_VERSION}" ...
2
votes
1answer
137 views

What signal does X send to its clients when it receives SIGINT?

If I terminate the Xorg server with a SIGINT signal (eg. when I press Ctrl+C), what signal does it send to its clients?
1
vote
1answer
384 views

How can I return a specific error code at this point in my TCL script?

I have a TCL expect script that runs a scp command for uploading a config file to my DNS server: #!/usr/bin/expect -f set config "~/dnsmasq.conf" spawn /usr/bin/scp "$config" ...
2
votes
3answers
5k views

How to copy or read the return value (exit status) from AWK script into the shell script (bash) to be used in if statement to compare

I want to read the error codes or the exit status of awk script into shell to use in if condition to compare for error handling my shell script looks something like: My script: #!/bin/sh awk -v ...
1
vote
3answers
125 views

How do I shutdown the system after a particular process exits

I am downloading some software; I can see the pid of the download process with top. Let's say it's 1001. How can I make it so that my computer shuts down after process 1001 exits?
8
votes
3answers
428 views

How do I capture the exit code / handle errors correctly when using process substitution?

I have a script that parses file names into an array using the following method taken from a Q&A on SO: unset ARGS ARGID="1" while IFS= read -r -d $'\0' FILE; do ARGS[ARGID++]="$FILE" done ...
4
votes
2answers
2k views

Unable to get the right exit code from a script

I have a script which connects to a remote server via SFTP and get some file from there. My script goes like this: /usr/bin/sftp USER@remote.server.com <<EOF lcd /dir1/dir2/dir3 cd ...
4
votes
0answers
3k views

Proper usage of EXIT & ERR traps in bash scripts [closed]

I'm working on a bash script and as I've been going I've learned about traps, signals, function return codes and other such features I've not previously used. I may be thinking about things ...