We have a simple little script to calculate time remaining before some target date.
We encourage our end-users to run this script during the lead-up to any scheduled maintenance, where we place a maintenance reservation. Requesting time through Slurm greater than that remaining puts a job in the queue until after the maintenance is complete.
I’ve recently learned that /etc/profile.d/motd.sh can be used to include this script output with the motd message in the shell when some logs in.
Is there a way to directly use the /etc/profile.d/motd.sh with the ood motd widget?
I am not familiar with any way to include scripts directly in the dashboard widgets, but you might be able to get around this using the ERB support in motd, that is by having ruby code run the script with
<% time_remaining = `/path/to/myscript.sh` %>
Look out for downtime in <%= time_remaining %> hours
There are several different ways to execute commands in ruby depending on the specific case, but backticks are the most straightforward and a good thing to try first. If your motd.sh file also generates the surrounding text, the motd.md.erb file could be as simple as <%= `/etc/profile.d/motd.sh` %>.
You can customize that with the MOTD_PATH configuration (in the same place as MOTD_FORMAT), so it is entirely up to you, and what works best for your workflows and organization. The examples in the docs often place it at /etc/motd but I think that is more for minimalism than anything else. It is probably good practice to have it somewhere in /etc/ to minimize the chance it is ever accidentally modified, but there is nothing enforcing that.
The widget in /etc/ood/config/apps/dashboard/app/views/widgets/_motd.html.erb is just rendering the contents of the file at MOTD_PATH, so you shouldn’t have to modify that at all.
I also want to mention that including the .md.erb extension to that file is totally optional. Because you already have to configure the formatter you want, the extension on the file does not affect anything. So it could just as easily be motd as long as that is reflected in the MOTD_PATH variable.
Right now, my MOTD_PATH=/etc/motd
So, for ood, I’d do better to have /etc/motd.md.erb co-located with standard motd, and set
MOTD_PATH=/etc/motd.md.erb
Then I do have /etc/profile.d/motd.sh. So the simplest would be to just implement that file through the /etc/motd.md.erb as you suggested:
<%= /etc/profile.d/motd.sh %>
Yes that is all accurate. There could be some formatting things that you run into (I am guessing that the motd.sh script does not add any markdown features), which could make accessing the countdown script directly a better option, but that is totally up to you.
If you already have a motd file configured, then changing the MOTD_PATH will stop looking for that file in favor of motd.md.erb. Is that intended? Assuming you just want to edit the existing motd in light of the program output (or append the output of motd.sh to the end) then you may just want to include the erb snippet in your main motd file instead of making a second one. Since your MOTD_FORMAT is set to ‘markdown_erb’ the ERB will work just as well in motd or motd.md.erb.