Issue
This is part of bigger code that checking the OS version and choosing the correct condition by it.
( after checking OS version, it will go to this if condition: )
if [ "$AK" = "$OS6" ]
then
if [ "$(ls -la /etc/init.d/discagent 2>/dev/null | wc -l)" == 1 ]
then
/etc/init.d/discagent restart 2>&1 > /dev/null
/etc/init.d/discagent status |& grep -qe 'running'
if [ $? -eq 0 ] ; then
echo " Done "
else
echo " Error "
fi
fi
fi
If im hashing service discagent restart
the pipeline is passing.
But if im not hashing it then it hang and not given any errors, And on the output file it is showing only the second server (out of few) that its hang on, And not moving to the next server.
what could be the issue?
p. S while running it direct on the server it is working.
Solution
Run this script manually on the servers, that this script will be running on.
You can use xtrace
-x
which would show each statement before being executed, when you use with -v
with -x
so this would be -xv
and the statement would be outputted, and then the line after the output of the statement with the variables substituted before the code is substituted.
using -u
would show you the exact error when this occurs.
Another command is the trap
command to debug your bash script.
More information on the following webpage, https://linuxconfig.org/how-to-debug-bash-scripts
Answered By - Shaqil Ismail