用户登录时,bash 先自动执行系统管理员建立的全局登录 script:
/etc/profile
所以如果想实现题目的要求可以在 /ect/profile
中添加想要执行的命令.
例如我想实现远程登录成功后立即显示系统当前已经运行了多长时间, 可以修改文件 /ect/profile
, 添加如下代码:
cat /proc/uptime| awk -F. \'{run_days=$1 / 86400;run_hour=($1 % 864 00)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf(\"系统已运行:%d> 天%d时%d分%d秒\",run_days,run_hour,run_minute,run_second)}\'
于是登录成功后即可以显示:
系统已运行:100天8时45分27秒
参考网址:
Comments