展示类似这种登录信息
对于docker来说,登录有两种方式,一种是ssh登录,一种是docker exec命令进入。利用现有的motd机制,只能对于ssh 登录有效。motd机制介绍如下,以ubunt系统为例:
/etc/motd 文件里添加静态内容,所见既所得。
/etc/update-motd.d/ 目录下面添加一些脚本,该目录下文件以文件名开头数字顺序执行:
如果想对docker exec命令进入也生效,必须采用shell配置的方式,
比如添加 /etc/profile里,或者添加到 ~/.bashrc 里
source /etc/damodel_motd.sh
另,一种shell艺术字
apt update && apt install -y figlet
shell字体颜色设置:https://blog.csdn.net/yetugeng/article/details/89978787
cat /etc/damodel_motd.sh
#!/bin/bash
text=`figlet welcome to DaModel`
echo -e "\033[1;47;31m ${text} \033[0m"
printf "
"
echo -e "\033[7;1;34m 目录说明: \033[0m
"
printf "╔══════════════════════╦══════════╦═════╦═════════════════════════════════════════════════════════════════════════╗
"
printf "║目 录║名 称║速 度║说明 ║
"
printf "╠══════════════════════╬══════════╬═════╬═════════════════════════════════════════════════════════════════════════╣
"
printf "║/ ║系 统 盘║一 般║实例关机数据会丢失,会随保存镜像一起保存。 ║
"
printf "╠══════════════════════╬══════════╬═════╬═════════════════════════════════════════════════════════════════════════╣
"
printf "║/root/workspace/ ║本地数据盘║ 快 ║实例关机数据会丢失,可存放读写IO要求高的数据。但不会随保存镜像一起保存。 ║
"
printf "╠══════════════════════╬══════════╬═════╬═════════════════════════════════════════════════════════════════════════╣
"
printf "║/root/shared-storage/ ║网 盘║ 慢 ║可以实现多实例间的文件同步共享,不受实例开关机和保存镜像的影响。 ║
"
printf "╚══════════════════════╩══════════╩═════╩═════════════════════════════════════════════════════════════════════════╝
"
if [[ -n "$MOUNT_INFO" ]]; then
if [[ -f "/etc/mount_info.sh" ]]; then
/etc/mount_info.sh
fi
else
echo "未挂载云磁盘"
fi
printf "
"
printf "
"
if test -f "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"; then
cfs_quota_us=$(cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us)
cfs_period_us=$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us)
if [ $cfs_quota_us -ge $cfs_period_us ];then
cores=$((cfs_quota_us / cfs_period_us))
else
cores=0.$((cfs_quota_us * 10 / cfs_period_us))
fi
printf "CPU :%s 核心
" ${cores}
limit_in_bytes=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)
memory="$((limit_in_bytes / 1024 / 1024 / 1024)) GB"
printf "内存:%s
" "${memory}"
else
cores=$(cat /sys/fs/cgroup/cpu.max | awk '{print $1/$2}')
printf "CPU :%s 核心
" ${cores}
limit_in_bytes=$(cat /sys/fs/cgroup/memory.max)
memory="$((limit_in_bytes / 1024 / 1024 / 1024)) GB"
printf "内存:%s
" "${memory}"
fi
if type nvidia-smi >/dev/null 2>&1; then
gpu=$(nvidia-smi -i 0 --query-gpu=name,count --format=csv,noheader)
printf "GPU :%s
" "${gpu}"
fi
echo ""
echo -e "\033[1;31m 🔥🔥🔥💣 注意: 💣🔥🔥🔥 \033[0m "
echo -e "\033[7;1;31m 1.系统盘较小请将大的数据存放于本地数据盘或网盘中,重置系统时本地数据盘和网盘中的数据不受影响。 \033[0m "
echo -e "\033[7;1;31m 2./root/workspace/下内容,释放实例时不保存,制作镜像时也不保存。\033[0m "
echo -e "\033[7;1;31m 3.用户在创建云磁盘时可以选择是否随实例释放,如果有重要数据建议不要勾选'随实例释放'。\033[0m "
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。