1. 程式人生 > >linux系統監控用戶操作腳本

linux系統監控用戶操作腳本

code all pwd %s root gin who text 系統監控

linux系統監控用戶操作腳本:

###############################################################################
#2010/08/12 15:42

PS1="whoami@hostname:"‘[$PWD]‘

history

USER_IP=who -u am i 2>/dev/null| awk ‘{print $NF}‘|sed -e ‘s/[()]//g‘

if [ "$USER_IP" = "" ]

then

USER_IP=hostname

fi

if [ ! -d /etc/node ]

then

mkdir /etc/node

chmod 777 /etc/node

fi

if [ ! -d /etc/node/${LOGNAME} ]

then

mkdir /etc/node/${LOGNAME}

chmod 300 /etc/node/${LOGNAME}

fi

export HISTSIZE=4096

DT=date +" %Y%m%d_%H%M%S"

export HISTFILE="/etc/node/${LOGNAME}/${USER_IP}linux1$DT"

chmod 600 /etc/node/${LOGNAME}/node 2>/dev/null

#######################################################################

linux系統監控用戶操作腳本操作示例:

1.將此腳本加到/etc/profile文件後面

2.創建linux1用戶的相關的目錄
[[email protected] ~]# mkdir -p /etc/node/linux1
[[email protected] ~]# cd /etc/node/
[[email protected] node]# ll
total 4
drwxr-xr-x 2 root root 4096 Jun 1 01:24 linux1
[[email protected] node]# chmod -R 753 linux1/
[[email protected] node]# ll

total 4
drwxr-x-wx 2 root root 4096 Jun 1 01:24 linux1

3.創建linux1用戶,並用linux1用戶登錄系統做相關操作

4.當linux1用戶退出系統後,會在/etc/node/linux1下生產log,記錄此用戶的操作
[[email protected] linux1]# pwd
/etc/node/linux1
[[email protected] linux1]# ll
total 4
-rw------- 1 linux1 linux1 17 Jun 1 01:42 192.168.198.1linux1 20150601_014237

(此文件的格式為:登錄此系統用的IP地址 用戶 日期 時間)

5.創建linux2用戶和相關目錄

[[email protected] ~]# useradd linux2
[[email protected] ~]# passwd linux2
Changing password for user linux2.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

[[email protected] node]# pwd
/etc/node
[[email protected] node]# mkdir linux2
[[email protected] node]# ll
total 12
drwxr-xr-x 2 root root 4096 Jun 1 01:58 linux2
drwxr-x-wx 2 root root 4096 Jun 1 01:56 linux1
d-wx------ 2 root root 4096 Jun 1 01:55 root
[[email protected] node]# chmod 753 linux2/
[[email protected] node]# ll
total 12
drwxr-x-wx 2 root root 4096 Jun 1 01:58 linux2
drwxr-x-wx 2 root root 4096 Jun 1 01:56 linux1
d-wx------ 2 root root 4096 Jun 1 01:55 root
[[email protected] node]# cd linux2/
[[email protected] linux2]# ll
total 0

6.使用linux2用戶登錄操作系統做相關操作,當linux2用戶退出時,會在/etc/node/linux2目錄下記錄操作log
[[email protected] linux2]# pwd
/etc/node/linux2
[[email protected] linux2]# ll
total 4
-rw------- 1 linux2 linux2 30 Jun 1 01:59 192.168.198.1linux1 20150601_015928
[[email protected] linux2]# cat 192.168.198.1linux1\ 20150601_015928
id
hostname
df -hj
df -h
exit
[[email protected] linux2]#

至此linux系統監控用戶操作腳本創建完畢!

更多技術分享,請關註微信公眾號 Big Data課堂

技術分享圖片

linux系統監控用戶操作腳本