MOTD is displayed by the pam authentication module in modern linux distros, right after your login. No user script will run before that.
You can simply modify the motd file to clear the screen via terminal escape sequences. <esc>[2J<esc>[;H will clear the screen and jump up. Open your motd file with vim, press i (insert mode), press ctrl+v, press the esc button. You will see ^[. You just typed the ascii 27 escape character. Type [2J then ctrl-v esc again then [;H. Now press esc (without ctrl-v, this is to escape the insert mode in vi) then press shift+Z two times.
Your screen will be cleared on every vt100 compatible terminals.
Your another option is to disable motd in pam. Search for the pam_motd.so in the /etc/pam.d directory: grep pam_motd /etc/pam.d/* . Most possibly you will find something like
session optional pam_motd.so
Comment it out with #. Implement your own motd (cat the /etc/motd file in the init script of your choice). Of course now you can clear before cat.
1so I just tried editing my
/etc/motd
file and added[2J[;H
to the top of it and it just appeared as text on in the MOTD. – Jordan Davis – 2017-01-19T22:07:04.830If you (or somebody else reading this) don't like vim you can use the following: echo -e \e[2J\e[;H > motd2 && cat /etc/motd>>motd2 after that you will get a new motd2 (with clearscreen) which can be moved over the original. – goteguru – 2017-01-19T22:12:50.510
I use vim so it's good. One other quick question though. Could I add that to the 00-header file so that the "Welcome to Ubuntu...." info and the package updates aren't cleared out? – Jordan Davis – 2017-01-19T22:14:18.080
You can add it anywhere, its a terminal escape sequence. However if you modify system-managed files, the package manager may overwrite your version in the future. (I'm on gentoo, but ubuntu may warn you I don't know). – goteguru – 2017-01-19T22:17:04.713
Do I need to
echo
it in the bash script since its not text-based like the/etc/motd
I tried at the bottom of the commented lines in the00-header
file, and isn't working. – Jordan Davis – 2017-01-19T22:29:16.357If you want echo-magic you can use echo -e '\e[2J\e[;H' without vim. But if you modify the shell script anyway (which might be overwritten) you can use the simple clear command. – goteguru – 2017-01-19T22:57:19.903
Yeah I ended up just doing
echo -e "[2J[;H"
in the00-header
it won't get overwritten there so should be good. – Jordan Davis – 2017-01-19T23:09:08.177