Skip to content

Conversation

@KaushikMalapati
Copy link
Contributor

@KaushikMalapati KaushikMalapati commented May 13, 2025

Description

  • Checking three ping exit codes directly
  • In six places, uses bash parameter expansion instead of sed to remove -ipmi, -ana, and -fez suffixes
  • Using the -r flag with read
  • Using grep -c instead of piping grep to wc -l
  • Removing $ from arithmetic expressions
  • Putting an OR expression in braces (SC2235)
  • Moving variable outside of printf format
  • Removing useless echo
  • Quoting literal braces in sed expression (SC1083)

Motivation and Context

https://jira.slac.stanford.edu/browse/ECS-5216

How Has This Been Tested?

Interactively. latest-released serverStat has identical output to below

(pcds-5.9.1) [kaushikm@psbuild-rhel7-03 scripts]$ ./serverStat --help
usage: ./serverStat <servername> [command]

Script to check status of servers & reboot/power cycle them using
the psipmi command

Default command is 'status', list of commands:
status  : print power status of machine, try to ping interfaces
on      : power machine on
off     : power machine off
cycle   : power cycle machine, waits 10 seconds in the off state
reset   : reset machine (ideally try that before power cycling)
console : open the ipmi console where possible
expert  : display info and run checks on server
(pcds-5.9.1) [kaushikm@psbuild-rhel7-03 scripts]$ ./serverStat fake-rec-ipmi off
This is a recorder, better not to power cycle unless necessary, try to reset first. Quit?  fake-rec off
yes
quit now
(pcds-5.9.1) [kaushikm@psbuild-rhel7-03 scripts]$ ./serverStat fake-drp-fez cycle
serverStat cycle is not supported for DRP nodes as the underlying psipmi power off or psipmi power cycle commands will disable the ipmi card. Instead, use the web interface as described on:

https://confluence.slac.stanford.edu/display/PSDMInternal/Debugging+DAQ#DebuggingDAQ-IPMI
(pcds-5.9.1) [kaushikm@psbuild-rhel7-03 scripts]$ ./serverStat ctl-mfx-wave8-fez status
psbuild-rhel7-03 may not be able to connect to IPMI on ctl-mfx-wave8-ipmi
ctl-mfx-wave8 is powered on
ctl-mfx-wave8 is a server with IP: 172.21.72.193 (ping success: 1), 172.21.24.47 (cannot ping from machine without fez)
cds interface is up
(pcds-5.9.1) [kaushikm@psbuild-rhel7-03 scripts]$ sshcd mfx-daq
===============================================================================
This is a Federal computer system and is the property of the United States
Government. It is for authorized use only. Users (authorized or unauthorized)
have no explicit or implicit expectation of privacy.

By using this system you expressly consent to the terms and conditions in
https://www.slac.stanford.edu/comp/policy/use.html
===============================================================================
Current working directory: /cds/home/k/kaushikm/et/scripts
[kaushikm@mfx-daq scripts]$ ./serverStat ctl-mfx-wave8-fez status
ctl-mfx-wave8 is powered on
ctl-mfx-wave8 is a server with IP: 172.21.72.193 (ping success: 1), 172.21.24.47 (ping success: 1)
cds&fez interfaces are up
[kaushikm@mfx-daq scripts]$ ./serverStat 172.22.1.1
No device of this name found, exiting...
[kaushikm@mfx-daq scripts]$ ./serverStat event2
server for event2 is: daq-mfx-dss03
event2 is powered on
daq-mfx-dss03 is a server with IP: 172.21.72.27 (ping success: 1), 172.21.24.39 (ping success: 1)
cds&fez interfaces are up
[kaushikm@mfx-daq scripts]$ ./serverStat event9
dss node not found for event9, exiting...
[kaushikm@mfx-daq scripts]$ ./serverStat ctl-mfx-wave8-fez expert
Host netconfig entry:
-------------------------------------------------
        name: ctl-mfx-wave8
        subnet: cds-mfx.pcdsn
        Ethernet Address: b4:2e:99:ad:fc:66
        IP: 172.21.72.193
        PC#: 98997
        Location: B999 H4.5 (MFX) L47 E12
        Contact: uid=aoarias,ou=People,dc=reg,o=slac
        Description: Ciara AMD7282
        DHCP parameters:
                filename "pxe/uefi/shim.efi";
        Puppet Classes:

Checking IPMI power status:
-------------------------------------------------

PCDS IPMI Tool
System power status
Chassis Power is on

Checking host/ipmi/fez network interfaces are online:
-------------------------------------------------
ctl-mfx-wave8 pings.
ctl-mfx-wave8-ipmi pings.
ctl-mfx-wave8-fez pings.

Red Hat Version:
-------------------------------------------------
el7

SLAC PCI Hardware:
-------------------------------------------------
c1:00.0 Signal processing controller: SLAC National Accelerator Lab TID-AIR AXI Stream DAQ PCIe card

Network PCI Hardware:
-------------------------------------------------
01:00.0 Ethernet controller: Intel Corporation Ethernet Controller 10G X550T (rev 01)
01:00.1 Ethernet controller: Intel Corporation Ethernet Controller 10G X550T (rev 01)

Leutron PCI Hardware:
-------------------------------------------------


IOC Processes:
-------------------------------------------------
PID    USER      SIOC                      COMMAND   HOSTNAME            PORT
2856   mfxioc    caRepeater                procServ  ctl-mfx-wave8       30000
3146   mfxioc    ioc-mfx-pgpw8-01          procServ  ctl-mfx-wave8       39100

PCDS Drivers:
-------------------------------------------------
#!/bin/bash
# For V6 driver:
     export SLAC_AES_VER=v5.16.0
source /reg/d/iocCommon/rhel7-x86_64/common/startup.cmd
[kaushikm@mfx-daq scripts]$ ping ctl-mfx-wave8
PING ctl-mfx-wave8.pcdsn (172.21.72.193) 56(84) bytes of data.
64 bytes from ctl-mfx-wave8.pcdsn (172.21.72.193): icmp_seq=1 ttl=64 time=0.060 ms
^C
--- ctl-mfx-wave8.pcdsn ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.060/0.060/0.060/0.000 ms
[kaushikm@mfx-daq scripts]$ ping ctl-mfx-wave8-ipmi
PING ctl-mfx-wave8-ipmi.pcdsn (172.21.72.194) 56(84) bytes of data.
64 bytes from ctl-mfx-wave8-ipmi.pcdsn (172.21.72.194): icmp_seq=1 ttl=64 time=0.384 ms
^C
--- ctl-mfx-wave8-ipmi.pcdsn ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.384/0.384/0.384/0.000 ms
[kaushikm@mfx-daq scripts]$ ping ctl-mfx-wave8-fez
PING ctl-mfx-wave8-fez.pcdsn (172.21.24.47) 56(84) bytes of data.
64 bytes from ctl-mfx-wave8-fez.pcdsn (172.21.24.47): icmp_seq=1 ttl=64 time=0.063 ms
^C
--- ctl-mfx-wave8-fez.pcdsn ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.063/0.063/0.063/0.000 ms
[kaushikm@mfx-daq scripts]$ netconfig search ctl-mfx-wave8-ana

Found 0 entries that match ctl-mfx-wave8-ana.
[kaushikm@mfx-daq scripts]$ serverStat aq-mfx-pgp02
Host ('daq-mfx-pgp02'
'daq-mfx-pgp02'
'daq-mfx-pgp02') not found in netconfig, exiting...
[kaushikm@mfx-daq scripts]$ serverStat aq-mfx-pgp22
No device of this name found, exiting...
[kaushikm@mfx-daq scripts]$ serverStat ioc-mfx-qadc
ioc-mfx-qadc is powered on
ioc-mfx-qadc is a server with IP: 172.21.72.188 (ping success: 1), 172.21.24.46 (ping success: 1)
cds&fez interfaces are up
[kaushikm@mfx-daq scripts]$ serverStat oc-mfx-qadc
server for oc-mfx-qadc is: ioc-mfx-qadc
oc-mfx-qadc is powered on
ioc-mfx-qadc is a server with IP: 172.21.72.188 (ping success: 1), 172.21.24.46 (ping success: 1)
cds&fez interfaces are up

Where Has This Been Documented?

@KaushikMalapati KaushikMalapati marked this pull request as ready for review May 13, 2025 07:43
@KaushikMalapati KaushikMalapati requested review from a team as code owners May 13, 2025 07:43
@KaushikMalapati KaushikMalapati removed the request for review from a team May 13, 2025 07:43
@KaushikMalapati
Copy link
Contributor Author

All the output I've pasted is from my branch, and is identical to the output from the current serverStat. No urgency to review this, but I would appreciate guidance on further testing this important script.

@ZLLentz
Copy link
Member

ZLLentz commented May 13, 2025

Yeah this is one of the more important scripts so we need to do some diligence

@ZLLentz
Copy link
Member

ZLLentz commented May 14, 2025

I suspect what we need to do for robust testing here is:

  • pick a test server to try all the options on
  • get some more eyes on it

I'll review the code at least now

Copy link
Member

@ZLLentz ZLLentz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the shellcheck edits seem clean/clear/correct

We need to pick a server to mess with, maybe the maker space ctl servers are good targets

@KaushikMalapati
Copy link
Contributor Author

@ZLLentz I tried the non-power commands on ctl-tst-dev-03 (status, console, expert) and the power-related commands (off, on, cycle, and reset) on ctl-tst-dev-02, all successfully. Any suggestion on who else should look at this?

@tangkong
Copy link
Contributor

Aside: I find it disorienting that the subcommand comes after the server argument

@ZLLentz
Copy link
Member

ZLLentz commented May 14, 2025

I'm going to request a review from the new @pcdshub/engtools-team that I forgot to merge in #291 and I forgot to announce, I think I'd like one more person to confirm we're good to go here.

I will put my approval on and wait for one more.

@ZLLentz ZLLentz requested a review from a team May 14, 2025 22:13
ZLLentz
ZLLentz previously approved these changes May 14, 2025
Copy link
Member

@ZLLentz ZLLentz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, I think this has been tested enough and looks good.
+1 more approval from engtools-team would be enough to merge I think

@KaushikMalapati KaushikMalapati requested a review from a team May 14, 2025 22:18
@silkenelson
Copy link
Collaborator

The server name is the first argument as it default (or at least should default to 'status') and I was too lazy check for the number of arguments and change how the first argument is used depending on that and/or good enough to just use -- or so.

@KaushikMalapati KaushikMalapati requested a review from vespos July 15, 2025 20:25
silkenelson
silkenelson previously approved these changes Sep 12, 2025
Copy link
Collaborator

@silkenelson silkenelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe enough tests have been done.
Sorry for taking such a long time that you now have to clean up merge conflicts.

@KaushikMalapati KaushikMalapati dismissed stale reviews from silkenelson and ZLLentz via c56231a September 12, 2025 21:13
@KaushikMalapati
Copy link
Contributor Author

Merge conflict was easy to fix. I tested it by doing serverStat expert on an unpingable fez, a pingable fez, and a server without a fez netconfig entry.

@KaushikMalapati KaushikMalapati merged commit fbcd2b8 into pcdshub:master Sep 15, 2025
2 checks passed
@KaushikMalapati KaushikMalapati deleted the shellcheck-serverStat branch September 15, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants