1826378 Members
4188 Online
109692 Solutions
New Discussion

script not working

 
SOLVED
Go to solution
kholikt
Super Advisor

script not working

I have written one script to do some omniback reporting but the script is not running at all no error message and I have to ctrl-c to break it.
abc
3 REPLIES 3
harry d brown jr
Honored Contributor
Solution

Re: script not working

set -x

and rerun it

live free or die
harry d brown jr
Live Free or Die
Bill Hassell
Honored Contributor

Re: script not working

You'll need to trace the execution to find out where the hang occurs, probably in one of the omniback commands. I would suspect any media query commands. But to be sure, add the -x option to all program parts including functions. The way I do this is to add a debug test to the beginning of every function and also to the beginning of the main program:

#!/usr/bin/sh

# To trace this script's operation, set the variable
# DEBUG temporarily as in:
# DEBUG=1 my_script options...
DEBUG=${DEBUG:=NotSet}
[[ $DEBUG = NotSet ]] || set -x

...

function MyFunction
{
DEBUG=${DEBUG:=NotSet}
[[ $DEBUG = NotSet ]] || set -x

...

}

etc...

Repeat the $DEBUG test in every function (in yours: getinfo_std getinfo_lib standalone library). When you run the script normally, the debug statements are inactive. When you run with the temprary variable DEBUG set on the command line (don't set or export DEBUG on a separate line) the script will trace every step onto stderr. If you want to pipe the results to pg or more, be sure to redirect stderr to stdout as in:

DEBUG=1 my_script options 2>&1 | more

For readability, you may want to change all your grave accent (reverse apostrophes) to $(...) as the grave accent construct has been deprecated for many years (see man sh-posix or man ksh). Example:

change: HOST=`hostname`
to: HOST=$(hostname)

Grave accents cannot be nested as in:

MYIP=$(getip $(hostname))


Bill Hassell, sysadmin
Peter Godron
Honored Contributor

Re: script not working

Hi,
depending on the size/complexity of the script either add debug statements (echo "this is proces...") and/or set +x
set +x output can be a bit confusing, especially in loops.