Cyclenerd / static_status

🚦Bash script to generate a static status page.
https://cyclenerd.github.io/static_status/
GNU General Public License v3.0
536 stars 71 forks source link

fix: script checks not always working #32

Closed kevinpapst closed 3 years ago

kevinpapst commented 3 years ago

Notes

I had some problems when setting up all of my tests.

One is simple: the /bin/true does not exist on all systems (here Mac) while true and false worked on several servers I tried. Not sure though which one is more cross-compatible.

The other one is a bit trickier and I might be wrong, as my bash-foo is really far away from being good. But no matter what I tried, all script tests failed on my Mac and on my server. I am not sure why, either the way I use it or becuase I appended parameters to the script or because the if-evaluation in the code wasn't ideal?

Just for example, I added the following test which failed with your if before:

script;mysqladmin ping -h 127.0.0.1 --connect-timeout 2|Database cluster

After the change your examples and my added script checks worked.

Here is the raw output of the script check mysqladmin ping -h 127.0.0.1 --connect-timeout 2 that I use:

Bildschirmfoto 2021-08-12 um 17 25 00

The command might be confusing, it shows errors (which can be ignored) but for the check only the exit code is relevant.

UPDATE AFTER MORE TESTING

Maybe the entire if change is not necessary, there seems to be a difference between

if $cmd &> /dev/null; then

and

if "$cmd" &> /dev/null; then

The first one works in my case (error message but exit code 0 leads to operational), while the second one breaks (leads to outage). Do you happen to know the difference?

I could revert most of my changes and only remove the ". But before putting any more effort into this, I'd like to get some feedback.

Cyclenerd commented 3 years ago

The script function is intended to start shell scripts not command. Unfortunately, the description is not very good from myself. I will try to explain it better. So create a script (example mysql.sh) and insert your commands here. Add this mysql.sh to your checks,

kevinpapst commented 3 years ago

Ok, accepted. I feared that this will be your answer. I'd like to avoid extra scripts, a lot of checks could be squeezed into these one-liners 😁 especially as your own example includes a one-liner call to a command.

Can you explain the different behavior? Is it really intended that it does not work as I hoped it would? Or is that by accident? I could only find an explanation that the " should be safer with commands that include space.

Any opinion about true vs /bin/true?

Cyclenerd commented 3 years ago

It is really only intended to start scripts. I have also removed the example with /bin/true.

kevinpapst commented 3 years ago

Ok, then I will add extra scripts for the checks. Thanks for your feedback.