失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > linux用户登陆时 配置自动加载执行shell脚本的做法

linux用户登陆时 配置自动加载执行shell脚本的做法

时间:2023-04-09 01:48:58

相关推荐

linux用户登陆时 配置自动加载执行shell脚本的做法

通过/etc/motd文件中直接加入脚本内容或在/etc/profile.d文件夹中加入.sh执行脚本文件,可以实现在linux用户登陆后,自动执行脚本内容。大家观察/etc/profile.d文件夹下,有许多我们非常熟悉的内容,包括vim、less等:

[elon@spark ~]$ ls /etc/profile.d/colorls.csh gnome-ssh-askpass.csh less.csh vim.shcolorls.sh gnome-ssh-askpass.sh less.shwhich2.shglib2.csh lang.cshudisks-bash-completion.shglib2.shlang.shvim.csh

这些都是在用户登录时,会自动加载的执行脚本,而在系统开机时自动加载的脚本就不再这人配置和显示了,这里主要介绍用户登陆时需要执行的脚本配置。下面通过两个示例来具体看看如何配置用户登录时自动加载的执行脚本。

示例一:

通过root用户 输入命令vim /etc/motd修改motd文件 ,在该文件中加入内容echo "Hello,Welcome to Linux!"

退出用户,下次登陆显示结果:

[elon@spark py]$ exitlogoutLast login: Sat Jan 27 23:15:01 from 192.168.1.1echo "Hello,Welcome to Linux!"[elon@spark ~]$

示例二:

通过在/etc/profile.d文件夹中加入shell脚本,实现同样的效果:

进入该目录,创建test.sh文件:

[root@spark elon]# cd /etc/profile.d/[root@spark profile.d]# vi test.shecho "Hello,The twice time to login in linux!""test.sh" [New] 1L, 47C written

[root@spark profile.d]# exitexit[elon@spark ~]$ exitlogoutLast login: Sun Jan 28 01:56:46 from 192.168.1.1echo "Hello,Welcome to Linux!"Hello,The twice time to login in linux![elon@spark ~]$

转载请注明出处:/coder__cs/article/details/79184544

本文出自【elon33的博客】

如果觉得《linux用户登陆时 配置自动加载执行shell脚本的做法》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。