C Shell(tcsh)
修改/etc/.cshrc文件(文件不存在创建即可):
vi /etc/.cshrc
在文件中加入以下内容,将其中的192.168.100.90替换为资源的IP:
以上在记录登录日志的时候作了判断,保证了当用户使用tcsh命令切换shell的时候不会记录登录日志。
# Add content in /etc/.cshrc
# Log C shell(tcsh) user login and commandhistory
set up_client_ip=`(who am i|cut -d\(-f2|cut -d\) -f1)`
set up_flag=`echo $up_client_ip|awk -F '($1~/[0-9]+.[0-9]+.[0-9]+.[0-9]+/)'`
if ( $up_flag == "" ) then
set -r up_client_ip=`grep"$up_client_ip" /etc/hosts|cut -f1`
else
set -r up_client_ip=`(who am i|cut -d\(-f2|cut -d\) -f1)`
endif
set -r up_nowtime=`(date +"%Y-%m-%d%T")`
if ( $user == `(id|cut -d\( -f2|cut -d\)-f1)` && "$0" == "tcsh" ) then
echo >/dev/null;
else
logger -p user.notice --class=\"HOST_LOGIN\" type=\"2\" time=\"$up_nowtime\" src_ip=\"$up_client_ip\" dst_ip=\"192.168.100.90\" primary_user=\"\" secondary_user=\"`id|cut-d\( -f2|cut -d\) -f1`\" operation=\"\" content=\"loginsuccessful\" authen_status=\"Success\" log_level=\"1\" session_id=\"$$\" >/dev/null
endif
alias precmd 'logger -p user.notice --class=\"HOST_COMMAND\" type=\"3\" time=\"`date+"%Y-%m-%d %T"`\" src_ip=\"$up_client_ip\" dst_ip=\"192.168.100.90\" primary_user=\"\" secondary_user=\"`id|cut -d\( -f2|cut -d\) -f1`\" operation=\"`history 1 | cut -f3-`\" content=\"command\" authen_status=\"\" log_level=\"1\" session_id=\"$$\">/dev/null'
C Shell(csh)
以下几点:
配置如下:
修改/etc/.login文件(文件不存在创建即可):
vi /etc/.login
在文件中加入以下内容,将其中的192.168.100.90替换为资源的IP。
# Add content in /etc/.login
# Log C shell(csh)user login and commandhistory
switch ($shell)
case */csh:
set up_nowtime=`date +"%Y-%m-%d %T"`
set up_client_ip=`(who am i|cut -d\( -f2|cut -d\) -f1)`
set up_flag=`echo $up_client_ip|awk -F '($1 ~/[0-9]+.[0-9]+.[0-9]+.[0-9]+/)'`
if ( $up_flag == "" ) then
set up_client_ip=`grep "$up_client_ip" /etc/hosts|cut -f1`
endif
logger -p user.notice -- class=\"HOST_LOGIN\"type=\"2\" time=\"$up_nowtime\" src_ip=\"$up_client_ip\" dst_ip=\"192.168.100.90\" primary_user=\"\" secondary_user=\"`id|cut -d\( -f2|cut -d\) -f1`\" operation=\"\" content=\"login successful\" authen_status=\"Success\" log_level=\"1\" session_id=\"$$\" >/dev/null
breaksw
default:
breaksw
endsw
至此,Solaris下bash、sh、ksh、tcsh、csh环境下的登录日志、操作日志的配置方法已全部写完。后续发布:
Solaris系统下各个shell的启动文件;
Solaris下操作日志实现方法(PROMPT_COMMAND、trap、trap函数、precmd)的测试结果;