0

After designing a simple shell/bash based backup script on my Ubuntu engine and making it work, I've uploaded it to my Debian server, which outputs a number of errors while executing it.

What can I do to turn on "error handling" in my Ubuntu machine to make it easier to debug?

3 Answers 3

2
  • ssh into the server
  • run the script by hand with either -v or -x or both
  • try to duplicate the user, group, and environment of the error run in your terminal window
    If necessary, run the program with something like "su -c 'sh -v script' otheruser

You might also want to pipe the result of the bad command, particularly if run by cron(8), into /bin/logger, perhaps something like:

sh -v -x badscript 2>&1 | /bin/logger -t badscript

and then go look at /var/log/messages.

Sign up to request clarification or add additional context in comments.

Comments

2

Bash lets you turn on debugging selectively, or completely with the set command. Here is a good reference on how to debug bash scripts.

The command set -x will turn on debugging anywhere in your script. Likewise, set +x will turn it off again. This is useful if you only want to see debug output from parts of your script.

Comments

1

Change your shebang line to include the trace option:

#!/bin/bash -x

You can also have Bash scan the file for errors without running it:

$ bash -n scriptname

1 Comment

@Industrial: I can be a lot more helpful if I knew what the specific error messages were.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.