Skip to content

Tag: bash

java.lang.NullPointerException and return code

I’m running some java binary from bash like: run_me.sh but inside application I get java.lang.NullPointerException, howewer return code is 0, but I need some non zero exit code to understand from bash that application failed. What is the proper way to handle such cases? Update: Here is an exxample of &#…

Shell Mount and check directionairy existence

Just looking for some help with my mounting shell script, wondering if anyone could advice me on how to make it check for the directory at the mount point exists and is empty, or is created by the script if it does not exist Answer Your use of grep will return any mountpoint that contains the string /myfilesy…

Bash | pipe to bash function

In the attempt to pipe to a Bash function, I wrote this: However, in another context I am receiving the correct output plus this error message: “Segmentation fault (core dumped)”. Trying to debug it I ask if there is something wrong the way I am writing the code inside the function in order to get…

Error concatenating var in bash script

I have a bash script that searchs for password for unrar files. I would like to concatenate result and at the end of the script notify result of execution, but I don´t know why final_result var outputs “INIT-END”. Why does not concatenate in search_pass_and_unrar function? Thanks a lot, best regar…

Azure VM Linux Ubuntu backup agent – Deployment failed

We have two Ubuntu (14.04) Linux server VMs on Azure hosting. Currently trying to setup the backup service within Azure for these machines. I have followed this guide and have the agent up and running. When running “waagent -version” in bash output shows: When then attempting to enable the backup …

The Linux timeout command and exit codes

In a Linux shell script I would like to use the timeout command to end another command if some time limit is reached. In general: But I also want that my shell script exits when the command is failing for some reason. If the command is failing early enough, the time limit will not be reached, and timeout will…

Exit whole script from code block { }

I have the following script: But the problem is that the {} block is exiting and not the whole script. How can I make the whole script exit? Answer Add the following line after your tee command: test ${PIPESTATUS[0]} -eq 0 || exit ${PIPESTATUS[0]} Reference Link: https://stackoverflow.com/a/34386000/2357256

How do I classify files in Linux server by their names?

How can use the ls command and options to list the repetitious filenames that are in different directories? Answer You can’t use a single, basic ls command to do this. You’d have to use a combination of other POSIX/Unix/GNU utilities. For example, to find the duplicate filenames first: This means …