1、创建linux系统账户及密码

#/bin/sh
#创建用户
useradd -s /sbin/nologin  -g sftp $1
#产生六位随机密码
password=`date +%s |sha256sum |base64 |head -c 6 ;echo`
#创建用户密码
echo "$password" |passwd --stdin $1
#帐号密码输出到文件
echo "user:$1 passwd:$password"  >>user

2、查询当前系统每个进程的线程数

#!/bin/bash
for pid in `ps -ef |grep sshd|grep -v grep|grep sshd|awk '{print $2}' `
do
   echo "$pid"  >/tmp/a.txt        #将sshd的进程号输入到a文件
   cat /proc/$pid/status |grep Threads >/tmp/b.txt #将各个进程下的线程数输入了b文件
   paste /tmp/a.txt /tmp/b.txt   #以列的形式展示a.txt b.txt内容
done 
sort -k3 -rn

3、自动kill firefox程序

#!/bin/bash

#

#***********************************************************************************************************************

# Author:Simon Chan

# Data:2024-01-23

# Update Data:2024-01-23 11:30:00

# Description:The script will automatically kill Firefox processes that have been running for more than 7 days.

# Copyright (C):2024 ALL rights reserved

# Version 1.0

#***********************************************************************************************************************

#

## Define base variable

log_file="/var/log/system/check_firefox.log"

dateinfo=$(date +"%Y-%m-%d %H:%M:%S")

## Main program

process_list=$(ps -eo pid,user,etimes,cmd --no-headers | awk '/firefox/ && $3 >= 604800 {print $1,$2,$3,$4}' |grep -v awk)

if [ ! -z "$process_list" ]; then

    echo "${dateinfo} [Process List]" >> $log_file

    while read -r pid user etimes cmd; do

        if kill "$pid"; then

            cat >> "$log_file" << EOF

$pid $user $etimes $cmd

EOF

        fi

    done <<< "$process_list"

else

    cat >> "$log_file" << EOF

${dateinfo} [Process List]

Do Nothing.

EOF

fi

标签: none

添加新评论