• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Creating a 'smart' motd?

smp

Diamond Member
Something easy, like:

hello $user

But, it's just a text file, soooo
and would $user work, if it was a script?
 
Don't know much about modifying motd in this way, but you could add something to their login shell's .profile/.cshrc/.login/.backrc/.bash_profile/zsh* or the system wide /etc versions.
 
Yeah, the MOTD isn't the place to do this. First off, it's not a script and thus is unaware of environment variables like $USER. Second, it's a system file, so user logon events won't be able to modify it.

But you could certainly put something in /etc/profile or one of the other startup scripts, as n0c suggested.
 
Yeah you could have something like /etc/motd-template, and have a script /etc/format-motd which does cat /etc/motd-template | sed -e "s/$user/$USER/g", and then have /etc/profile call that. I was thinking that you could just put $USER directly in the template and do cat /etc/motd-template | while read line; echo $line; done, but it looks like it doesn't interpret variables in that case, and I'm not sure how to go about that.
 
You could put make a fake MOTD script like /usr/bin/message and then execute it from the .bash_profile files.

. /usr/bin/message

Of course this is awkward...
 
You can append this sort of thing to /etc/profile, and it will get executed on login (supposing you run bash). On my slack 9.0 box here by default the /etc/profile script also executes all files ending in .sh in /etc/profile.d, so you can easily add system-wide scripts there. Perhaps that is what you're looking for? Just a simply bash script along the lines of:
#!/bin/sh
echo "Hello $USER"
If you wanted to get fancy, you could do up a perl script to figure out what time it is and have it alter the login message (good morning/afternoon/evening).

The following should work for that:
#!/usr/bin/perl
use strict;
use POSIX qw/strftime/;

$hour = strftime( "%h", localtime );
$user = $ENV{'USER'};
if ($hour < 12 && $hour >= 0) {
$message = "Morning";
} elsif ($hour >= 12 && $hour < 18) {
$message = "Afternoon";
} else {
$message = "Evening";
}
print "Good $message, $user.\n";
 
Back
Top