linux用户登陆时,配置自动加载执行shell脚本的做法 |
您所在的位置:网站首页 › 虚拟机shell程序在哪里编写的 › 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.sh colorls.sh gnome-ssh-askpass.sh less.sh which2.sh glib2.csh lang.csh udisks-bash-completion.sh glib2.sh lang.sh vim.csh这些都是在用户登录时,会自动加载的执行脚本,而在系统开机时自动加载的脚本就不再这人配置和显示了,这里主要介绍用户登陆时需要执行的脚本配置。下面通过两个示例来具体看看如何配置用户登录时自动加载的执行脚本。 示例一: 通过root用户 输入命令 vim /etc/motd修改motd文件 ,在该文件中加入内容 echo "Hello,Welcome to Linux!" 退出用户,下次登陆显示结果: [elon@spark py]$ exit logout Last login: Sat Jan 27 23:15:01 2018 from 192.168.1.1 echo "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.sh echo "Hello,The twice time to login in linux!" "test.sh" [New] 1L, 47C written [root@spark profile.d]# exit exit [elon@spark ~]$ exit logout Last login: Sun Jan 28 01:56:46 2018 from 192.168.1.1 echo "Hello,Welcome to Linux!" Hello,The twice time to login in linux! [elon@spark ~]$转载请注明出处:http://blog.csdn.net/coder__cs/article/details/79184544 本文出自【elon33的博客】 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |