Questions tagged [error-handling]

Use this tag for questions on how to handle errors generated in shell scripts.

Filter by
Sorted by
Tagged with
12
votes
1answer
30k views

What are the standard error codes in Linux?

When I write a code in bash for instance that copies a file, when the file doesn't exist, in the terminal I see an error similar to "file not found", if the script user isn't granted the permission ...
0
votes
1answer
2k views

“The specified directory 'media/fa/FAF9-!C03' is not valid” Error when trying to open USB sticks!

I have an ARM-based computer(nanopi m1) that has 3 USB ports that all work good with other devices like mouse, keyboard, wireless dongle. but when I try any USB flash memories it doesn't work! What's ...
78
votes
2answers
24k views

Why is pattern “command || true” useful?

I am currently exploring Debian packages, and I have been reading some code samples. And on every line in, for example, the postinst script is a pattern. some command || true another command || true ...
0
votes
1answer
222 views

apt vs apt-get error code

Strange thing I have here, when apt is locked by something. Respectively, the error codes don't match up. apt update seems to always return success 0, whereas apt-get update returns a proper error ...
2
votes
1answer
206 views

Fedora 15 updates

I have a dual booted system, and its been years since I have used the linux side. I am running Fedora15 and am trying to upgrade. I have tried yum install preupgrade and I get the error message ...
0
votes
2answers
728 views

Running command multiple times and trigger report on failure

I am trying to run the "make" command on my project 100 times. But, obviously I wouldn't be monitoring the results but I would like to know when the build fails. How would I go about making it ...
4
votes
3answers
4k views

Apache not binding to port 80?

I am having issues with Apache. I just installed Centos and waant to create a webserver of my own. I am following the directions of "the perfect server for centos 7.2" and came upon this error on my ...
0
votes
2answers
5k views

Why “syntax error near unexpected token”? [closed]

I have about 10k (approx 180x50x2) CSV files which I want to join together as following, but the inner for loop fails because of some syntax error; I cannot see the error in lastFile #!/bin/bash dir='...
0
votes
1answer
980 views

Script error “fork: retry: Resource temporarily unavailable”.. will failing lines be retried?

I'm running a ping script that backgrounds ping calls. #!/bin/bash for ip in $(seq 100 210); do ping x.x.x.$ip -c1 |grep "bytes from" |cut -d " " -f4|cut -d ":" -f1 & done If I receive ...
6
votes
1answer
2k views

Getting gcc piped-to-less to properly show colors on the terminal

I'm compiling a file with gcc (actually I'm make'ing, but never mind), which sends some colorized error messages to stderr. So, I do: gcc a.c 2>&1 | less but what I get is lines such as: a.c:...
3
votes
2answers
4k views

How fix E: Sub-process /usr/bin/dpkg returned an error code (2)?

When I'm trying to use apt-get install or upgrade I get that message! I tried this command sudo dpkg -C and got this results: The following packages are missing the list control file in the database, ...
2
votes
1answer
91 views

how to differentiate error returned while reading and for EOF in shell script

I have this task of uploading a delimited file and processing it. Once the processing is done, I either say its successful and if parsing fails, I need to throw the error. I'm reading this file line ...
3
votes
2answers
748 views

bash 'nounset' on sub-shell/child doesn't force main script to exit, how to workaround that globally?

With this script: tstNounset.sh #!/bin/bash set -x set -o nounset;set -u echo `echo $str` function FUNC1() { echo $str; };export -f FUNC1;bash -c FUNC1 function FUNC2() { set -u;echo $str; };export ...
0
votes
1answer
98 views

Error Update package ubuntu server

Hello i have this error when launch apt-get update command on my ubuntu server : how can i solve this? W: Impossibile scaricare alcuni file di indice: saranno ignorati o verranno usati quelli ...
0
votes
1answer
2k views

bash if condition on git command result

I have the following error due an invalid git command within my shell-script. git push blabla master results in fatal: 'blabla' does not appear to be a git repository I would like to respond to ...
1
vote
1answer
385 views

How to repeat a command n times then exit?

I want to automate an installation and I need to run the downloaded installer with gksu. I have tried: attempt=0 until gksu command; do attempt=$((attempt + 1)) if [ "$attempt" -gt 3 ]; ...
5
votes
3answers
807 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
4k views

I keep on getting a lots of error when doing sudo apt-get update. And it take a long time to complete

unique@my-pc ~ sudo apt-get update [sudo] password for unique: Err http://ppa.launchpad.net jessie/main amd64 Packages ...
0
votes
1answer
5k views

$? returns errorlevel 0 instead of 4

I just migrated a working Windows Batch script (.bat) to Unix Shell. Generally it's working quite nicely, however, I just realized that the errorlevel that is returned in Unix is wrong. From what I'...
0
votes
1answer
65 views

Is there a way to highlight the part of the line where an error is happening

I'm running this script and getting an error like this, but am having extreme difficulty detecting where exactly the error is happening. Is there an option when it points out exactly what characters ...
-2
votes
1answer
242 views

How to Do Error-trapping and Swapoff if Error/Warning?

Pseudocode where incomplete pseudo try-catch after cas' comment #!/usr/bin/env bash # http://askubuntu.com/q/799834/25388 # Use: `sh myScript`; sudo does not work with Matlab. #set -e # no ...
4
votes
2answers
7k views

How to Resolve the Insecure warning in Swapon?

I do #!/usr/bin/env bash # http://askubuntu.com/q/799834/25388 # http://stackoverflow.com/a/69808/54964 set -e SWAP_FILE="/media/masi/SamiSwapVirtual/.swap_file_20.7.2016" SIZE_MB=16000 dd if=...
1
vote
0answers
1k views

Mint 17.3: Your session has lasted less than 10 seconds

yesterday I executed 'sudo apt-get update && apt-get upgrade' and today I get the following error after the login Your session has lasted less than 10 seconds... syndaemon: no process found /...
1
vote
1answer
472 views

Ldap error doesn't redirect to file

I'm running a loop querying ldap server for a single dn every time, just to see if it's running okay. I want to output both the successful and unsuccessful responses to a file and while the former ...
2
votes
0answers
662 views

Error calling EVIOCSKEYCODE

I used journalctl -p 3 -xb and got this error message -- Logs begin at Thu 2016-06-23 22:48:08 AST, end at Sat 2016-06-25 13:15:23 AST. -- Jun 25 09:31:35 Almoullim systemd-udevd[268]: Error calling ...
2
votes
1answer
2k views

Echo input text amount limit?

I'm trying to do echo "foo foo foo ....[many many lines of foo here] foo" > "/Users/myname/destination.txt" through Applescript, but it returns an error when the characters in the lines of foo ...
3
votes
1answer
4k views

What does “DMA: Out of SW-IOMMU space” error mean?

First the link: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1060268 Since this affects the kernel and other Distros, what does this type of error mean and why it happens?
4
votes
4answers
6k 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 ...
9
votes
4answers
1k views

Bash program not executed if redirection would fail

In bash, I notice that if a command using redirection would fail, any programs which run prior to that are not run. For example, this program opens the file "a" and writes 50 bytes to file "a". ...
2
votes
2answers
109 views

Different error messages when using different strings in terminal

When I insert, for example, unix.stackexchange.com followed by Enter in terminal, I get the following error: unix.stackexchange.com: command not found This is ok and as I expected. But when I insert ...
6
votes
0answers
7k 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 ...
1
vote
2answers
4k views

Stopping .bashrc without exiting shell

My .bashrc file is modularized and I've got some error checking in it. In bash scripts, I typically have a function _errexit (or something similar) that I call when I detect an error and want to exit. ...
1
vote
1answer
482 views

Unwanted messages every time I attempt to login?

I am using Linux Mint Olivia and it worked fine for past couple of months but from yesterday it keep showing these message whenever I want to login to my PC: Keys: Press S to skip mounting or M for ...
2
votes
1answer
884 views

How to have a bash script perform a specific action on errors of _each_ command?

Similarly to set -e performs an exit on "uncaught" $? != 0, I'd like to have this event trigger the execution of another command, e.g. a logger call. How can this be done?
13
votes
2answers
12k views

How to trigger error using Trap command

I am using Ubuntu 12.04.2. I am trying to use "trap" command to capture abnormal or error in my shell script but I am also trying to manually trigger "Error" exit. I have tried exit 1, but it won't ...
1
vote
1answer
420 views

Catch unexpected input on single character read in bash [duplicate]

I have a bash script, which, at one point asks the user for confirmation. I do this by reading a single character, which is then transformed to lower case and checked if it is 'y'. If not, the script ...
-2
votes
2answers
4k views

Print out a log file with error from a cp command

I am writing an sh file I have this command cp test/*.txt NewDirectory/ from my understanding it will go one by one in the test folder 1.txt 2.txt 5.txt 6.txt but won't copy 3.txt 4.txt ...
1
vote
1answer
987 views

trap errors in bash scripts

I have several questions I want to understand in regards to error trap. why does the code below execute only 1 trap and not 2 and specifically only the code with "mydir2" and not "mydir1"? why at all ...
21
votes
6answers
8k views

How can I suppress output only if the command succeeds?

I would like to simplify the output of a script by suppressing the output of secondary commands that are usually successful. However, using -q on them hides the output when they occasionally fail, so ...
12
votes
5answers
91k views

How to catch an error in a linux bash script?

I made the following script: # !/bin/bash # OUTPUT-COLORING red='\e[0;31m' green='\e[0;32m' NC='\e[0m' # No Color # FUNCTIONS # directoryExists - Does the directory exist? function directoryExists {...
37
votes
3answers
39k views

chmod + silent mode + how force exit code 0 in spite of error

Is it possible execute chmod and ignore error from command Example ( remark file.txt not exsist to show the example ) When I type chmod 777 file.txt I get error on the output chmod: cannot ...
4
votes
1answer
706 views

Errtrace and local

I am using the following script: #!/bin/bash -Eu trap 'echo Hi' ERR exit_failure() { echo "Hello, World!" return 1 } sub_failure() { res=$(exit_failure) } sub_failure It results in the ...
25
votes
2answers
110k views

Where can I find a list of 'make' error codes?

I am trying to compile a program written in Fortran using make (I have a Makefile and, while in the directory containing the Makefile, I type the command $ make target, where "target" is a system-...
12
votes
5answers
13k views

Suppress server message in rsync

When I rsync or scp from a particular server I get a rather long message telling me the rules of the server. However when I setup regular pulls, I'd like to be able to suppress those messages in my ...
4
votes
2answers
4k views

Simultaneously check for empty output and successful exit status

I'd like to write the following test in an installer script1: if [ -n "`/etc/grub.d/30_os-prober`" ]; then install_dual_boot else install_linux_only fi However, it's also possible that 30_os-...
2
votes
2answers
10k views

Capture errors in a SFTP script

I have a sub sh file which puts receives an input of local directory and path to the remote directory and sends the file to the remote directory. If the remote path is invalid the error cannot be ...
11
votes
3answers
3k views

why bash increment: `n=0;((n++));` return error? [duplicate]

n=0; ((n++));echo "ret=$?;n=$n;" ((n++));echo "ret=$?;n=$n;" ((n++));echo "ret=$?;n=$n;" from n=1 on, ((n++)) works correctly, only when n=0, ((n++)) return error, and I am using a trap '' ERR that ...
0
votes
1answer
48 views

Warning message after updating

I have Linux Mint 17 Cinnamon edition and after updating using the terminal: sudo apt-get && sudo apt-get upgrade I got this warning message: ... Building dependency tree Reading ...
1
vote
1answer
85 views

Print nth pipeline command in bash

In bash, the PIPESTATUS array holds the return values of commands in a pipeline. Suppose that in the pipeline cmd1 | cmd2 | cmd3, the second command returns an error. Checking PIPESTATUS gives the ...
2
votes
1answer
324 views

crossplatformui error in Mint 11

Whenever I try to install something in my system it generally installs but shows some error related to "crossplatformui". I don't know what it is and how to remove it. I am printing here a sample ...