Fix bug in custom-upssched-cmd

Description

Hi,

the script /usr/local/bin/custom-upssched-cmd has an error on line 32:

32 if [ -n $(upsc $ident | grep "ups.status.*OL") ]; then
33 logger -t upssched-cmd "Shutdown not initiated as ups.status indicates ${ident} is ONLINE (OL)"
34 else
35 logger -t upssched-cmd "issuing shutdown"
36 /usr/local/sbin/upsmon -c fsd
37 fi

This supposed to test if the UPS is ONLINE and then issue a shutdown if not but the "-n" in line 32 inverts the logic. Removing the "-n" fixes this.

Problem/Justification

None

Impact

None

duplicates

is duplicated by

SmartDraw Connector

Katalon Manual Tests (BETA)

Activity

Bug Clerk 
May 24, 2019 at 4:27 PM

William Gryzbowski 
May 24, 2019 at 12:00 PM

that makes sense, thanks for figuring that out for us.

Former user 
May 24, 2019 at 8:24 AM

Hi,

I did it now with a "set -x" in the script:

 

 

Former user 
May 24, 2019 at 7:58 AM
(edited)

Hm, you are correct nethertheless it only works as expected when I remove the  "-n". If I am on battery and try the command I see in /var/log/messages:

May 24 09:45:32 grave upsmon[3440]: UPS ups on battery
May 24 09:45:35 grave upssched-cmd: Shutdown not initiated as ups.status indicates ups is ONLINE (OL).

And this should not work either and shows the problem:

 Edit: I found some documentation about this:

http://tldp.org/LDP/abs/html/comparison-ops.htm 

 

 Indeed, using "" around the $() fixes this.

William Gryzbowski 
May 23, 2019 at 4:30 PM

How so?

The current code logic says: if upsc says its ONLINE (OL), do no shutdown.
So it seems right to me.

What am I missing?

Complete

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

More fields

Katalon Platform

Created May 23, 2019 at 2:19 PM
Updated July 1, 2022 at 4:31 PM
Resolved June 25, 2019 at 11:32 PM