LoginSignup
11
6

More than 5 years have passed since last update.

サーバーログイン時に便利なメッセージを表示する

Posted at

みんなでいじりまわしてる Raspberry Pi が研究室にある。
今回はその Raspberry Pi にログインしたときに「こんな情報が表示しといたら便利かも」と思ったものを紹介する。

まず成果物

1__pi_raspberrypi_____zsh_.png

コード

print_login.sh
echo "
   __      ∧ ∧___
  /・・\    /(*゚ー゚) /\
  |   |  /| ̄∪∪ ̄|\/
  \__//    |  しぃ   |/
   人| /       ̄ ̄ ̄ ̄
    || /|    A_A __
    ヽ二ノ ⊂・ ・ ⊃▼⌒丶
               (ω__) )  ●|~*
                  U U. ~- 'U

                 _                 _
 _ __ ___   __ _(_)_ __ ___   __ _(_)
| '_ \` _ \ / _\` | | '_ \` _ \ / _\` | |
| | | | | | (_| | | | | | | | (_| | |
|_| |_| |_|\__,_|_|_| |_| |_|\__,_|_|
"

echo "Last Login User"
last |head -n5

echo ""
echo Currently $(w -h | wc -l) User Logged in
w -h

echo ""
echo "Machine Used"
df -h /dev/root

echo ""
echo "Command History"
tail .bash_history -n5

chmod +x print_login.sh しておく

.bashrc
sh ./print_login.sh

解説

AA(アスキーアート)

figlet コマンドで作成した。
https://github.com/cmatsuoka/figlet

ログインユーザ履歴

last |head -n5
-n5: 上位5つ

現在のログインユーザ

w -h
-h ヘッダーなし

ストレージ使用容量

df -h /dev/root
-h: 対象

直近コマンド履歴

tail .bash_history -n5
-n: 表示数

history -5 コマンドは .bashrc 内で呼べなかった。(ログイン中だから?)

その他

/etc/motd

静的な文字列を表示したい!ってだけであれば、
/etc/motd に表示したい内容を書くだけで良い。

.hushlogin

ユーザディレクトリに .hushlogin を置くとログイン情報を非表示にできる。

おわりに

他にもおすすめのものがあれば教えていただきたいです。

参考

Thanks!
http://qiita.com/ryosukes/items/5ca24a808ba9c9c272f6
http://qiita.com/suin/items/bc3fe53b3630a40e045b

11
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6