专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell脚本欣赏>

shell脚本 当用户进入系统时显示问候语

百度收藏 QQ搜藏

原文:http://bash.cyberciti.biz/time-and-date/greet-user-script/

运行这个脚本,当用户进入系统时就会显示问候语,如:早上好 中午好 晚上好等

Script first finds out current hour using date command
1)该脚本要先指定'date'命令的路径
2) 打开shell启动配置文件 ~/.bash_profile,把这个脚本(即你自己存放这个脚本的路径)添加到里面,示例:

/home/you/path/to/script
 
下面是该shell脚本的源代码:

#!/bin/bash
# Shell program which gets executed the moment the user logs in, it should
# display the message "Good morning", "Good Afternoon", or "Good Evening"
# depnding upon the time which the user logs in.
# =====================================================================
# Q. How to run this script as soon as user logs in?
# A. Open your bash startup file aka profile file - ~/.bash_profile
# and put path to this script in file as follow:
# . /path/to/greetings.sh
# -----------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
 
# get current hour (24 clock format i.e. 0-23)
hour=$(date +"%H")
 
# if it is midnight to midafternoon will say G'morning
if [ $hour -ge 0 -a $hour -lt 12 ]
then
  greet="Good Morning, $USER"
# if it is midafternoon to evening ( before 6 pm) will say G'noon
elif [ $hour -ge 12 -a $hour -lt 18 ]
then
  greet="Good Afternoon, $USER"
else # it is good evening till midnight
  greet="Good evening, $USER"
fi
 
# display greet
echo $greet
上一篇:shell脚本检查输入年份是否是闰年 下一篇:shell脚本 搜索打印UNIX/Linux系统里所有root权限的用户

power by soyo123 2007-2008