In your login shell's profile files you can set up some things that you will use during your session, and which only need to be done once. Some ideas:
- create a temporary file containing the IP address you connected from, later on you can include it in some scripts setting firewall rules.
- run ssh-agent, ask for your SSH keys, and store the SSH agent environment variables in a file.
- if that is a limited machine, and your co-workers want to be aware of each others logins, write(1) messages informing them of your login.
In a non-login shell's files (.bashrc
) you should configure your shell:
- Fancy prompt
- set aliases
- set history options
- define custom shell functions
- export environment variables, (maybe PAGER, EDITOR if system-wide settings suck)
- load ssh-agent variables saved in
.bash_profile
Usually, you would include .bashrc
from .bash_profile
with the following. Then login shell gets all your customizations, and .bash_profile
file does not have to duplicate things that are already in .bashrc
.
[[ -f ~/.bashrc ]] && . ~/.bashrc
I'm not sure why you have an aversion to doing this correctly - either on the server a la
PrintMotd no
PrintLastLog no
and
#/etc/pam.d/ssh
# Print the message of the day upon successful login.
# session optional pam_motd.so
Or adding ~/.hushlogin for each user.
Hint, for ~/.hushlogin, add it to /etc/skel so new user home directories are created with the file.
Update:
Without more information about your backup cron job, my only other suggestion is to redirect the output of the command to a file (or let cron capture it in email) and the output of the ssh session to /dev/null. Something like:
0 0 * * * ssh backuphost "backup_script_that_writes_to_a_log" >/dev/null
Or
0 0 * * * ssh backuphost "backup_command 2>&1" >/dev/null
I'd have to play around with the commands a bit, but that should get you started.
Best Answer
/etc/motd
is only read and not executed, so technically speaking, you cannot put shell commands in there.However, it's possible to execute a shell script at login time that will have the same result. This is usually achieved by adapting the
/etc/profile
script that is executed each time a user logs in. A useful practice is to put the command you want to be executed in a script named/etc/motd.sh
and call this script from/etc/profile
, usually at about the end of it.