Shell脚本——实用工具类

删除用户脚本.sh

#!/bin/bash
#
# Delete_User - Automates the 4 steps to remove an account
#
#################################################################
# 
# Define Functions
#
#################################################################
function get_answer {
#unset ANSWERASK_COUNT=0
#while [ -z "$ANSWER" ] # while no answer is given, keep askingdoASK_COUNT=$[ $ASK_COUNT + 1 ]
#case $ASK_COUNT in			# If user gives no answer in time allowed2)echo echo "Please answer the question."echo;;3)echo echo "One last try... please answer the question."echo;;4)echo echo "Since you refuse to answer the question..."echo "exiting program."echo#exit;;esac
#echo
#	if [ -n "$LINE2" ]thenecho $LINE1			# Print 2 linesecho -e $LINE2" \c"else					# Print 1 lineecho -e $LINE1" \c"fi
#
# Allow 60 seconds to answer before time-outread -t 60 ANSWERdone
#
# Do a little variable clean-up
#unset LINE1unset LINE2
#
}    #end of get_answer function
#
#################################################################
function process_answer {
#case $ANSWER iny|Y|YES|yes|yEs|yeS|YEs|yES)# If user answers "yes".do nothing.;;*)# If user answers anything but "yes", exit scriptechoecho $EXIT_LINE1echo $EXIT_LINE2echoexit;;esac## Do a little variable clean-upunset EXIT_LINE1unset EXIT_LINE2
#
} #End of process_answer function
#
################################################################
#
# End of Function Definitions
#
############### Main Script #################################
#
# Get name of User Account to check
#
echo "Step #1 - Determine User Account name to delete "
echo
LINE1="Please enter the username of the user"
LINE2="account you wish to delete from system:"
get_answer
USER_ACCOUNT=$ANSWER
#
# Double check with script user that this is the correct User Account
#
LINE1="Is $USER_ACCOUNT the user account"
LINE2="you wish to delete from the system?[ y/n ]:"
get_answer
#
############################################################
#
# Check that USER_ACCOUNT is really an account on the system
#
USER_ACCOUNT_RECORD=$(cat /etc/passwd | grep -w $USER_ACCOUNT)
#
if [ $? -eq 1 ]			# If the account is not found, exit script
thenecho echo "Account, $USER_ACCOUNT, not found."echo "Leaving the script..."echoexit
fi
#
echo
echo "I found this record:"
echo $USER_ACCOUNT_RECORD
echo
#
LINE1="Is this the correct User Account?[y/n]:"
get_answer
#
#
# Call process_answer function:
#	if user answers anything but "yes", exit script
#
EXIT_LINE1="Because the account, $USER_ACCOUNT, is not "
EXIT_LINE2="the one you wish to delete, we are leaving the script..."
process_anser
#
##############################################################
#
# Search for any running processes that belong to the User Account
#
echo
echo "Step #2 - Find process on system belonging to user account"
echo
echo "$USER_ACCOUNT has the following processes running: "
echo
#
ps -u $USER_ACCOUNT      #List the processes running
#
case $? in
1)			# No processes running for this User Account#echo "There are no processes for this account currently running."echo
;;
0)	# Processes running for this User Account.# Ask Script User if wants us to kill the processes.#unset ANSWER			# I think this line is not neededLINE1="Would you like me to kill the process(es)? [y/n]:"get_answer#case $ANSWER iny|Y|YES|yes|Yes|yEs|yeS|YEs|yES)    # if user answer "yes",#kill User Account processes#echo ## Clean-up temp file upon signals#trap "rm $USER_ACCOUNT_Running_Process.rpt" SIGTERM SIGINT SIGQUIT## List user processes runningps -u $USER_ACCOUNT > $USER_ACCOUNT_Running_Process.rpt#exec < $USER_ACCOUNT_Running_Process.rpt		# Make report Std Input#read USER_PROCESS_REC				# First record will be blankread USER_PROCESS_REC#while [ $? -eq 0 ]do# obtain PIDUSER_PID=$(echo $USER_PROCESS_REC | cut -d " " -f1 )kill -9 $USER_PIDecho "Killed process $USER_PID"read USER_PROCESS_RECdone#echo#rm $USER_ACCOUNT_Running_Process.rpt			# Remove temp report;;*) # If user answers anything but "yes", do not kill.echoecho "Will not kill the process(es)."echo;;esac
;;
esac
###################################################################################
#
# Create a report of all files owned by User Account
#
echo
echo "Step #3 - Find files on system belonging to user account"
echo
echo "Creating a report of all files owned by $USER_ACCOUNT."
echo
echo "It is recommended that you backup/archive these files."
echo "and then do one of two things:"
echo " 1) Delete the files"
echo " 2) Change the files' ownership to a current user account."
echo
echo "Please wait. This may take a while..."
#
REPORT_DATE=`date +%y%m%d`
REPORT_FILE=$USER_ACCOUNT"_Files_"$REPORT_DATE".rpt"
#
find / -user $USER_ACCOUNT > $REPORT_FILE 2>/dev/null
#
echo
echo "Report is complete."
echo "Name of report:	$REPORT_FILE"
echo "Location of report:     `pwd`"
echo
################################################################
#
# Remove User Account
echo
echo "Step #4 - Remove user account"
echo
#
LINE1="Do you wish to remove $USER_ACCOUNT's account from system? [y/n]:"
get_answer
#
# Cass process_answer function:
#	if user answers anything but "yes", exit script
#
EXIT_LINE1="Since you do not wish to remove the user account."
EXIT_LINE2="$USER_ACCOUNT at this time, exiting the script..."
process_answer
#
userdel $USER_ACCOUNT			# delete user account
echo
echo "User account, $USER_ACCOUNT, has been removed"
echo
#

当服务器线程数超过 2500 时自动 dump 线程数最高的 java 进程的内存及线程栈.sh

#!/usr/bin/env bash
# 来源: https://blog.csdn.net/qianghaohao/article/details/80379118 
# 服务器线程数达到 2500 以上时 dump 线程数最多的 java 进程的线程及内存
#
source ~/.bashrc
cur_thread_num=`ps -efL | wc -l`
if [ $cur_thread_num -le 2500 ]; thenexit 0
ficur_date=`date +"%Y-%m-%d_%H-%M-%S"`
cd ./dumpfile
# 服务器当前线程 dump 到文件:按照线程数由大到小排序显示
ps -efL --sort -nlwp > server_thread_dump_$cur_date
# dump 线程数最多的 jvm 的线程及内存
most_thread_num_pid=`cat server_thread_dump_$cur_date | sed -n '2p' | awk '{print $2}'`
nohup jstack -l $most_thread_num_pid > java_app_thread_dump_${cur_date}_pid_${most_thread_num_pid} &
nohup jmap -dump:format=b,file=java_app_mem_dump_${cur_date}_pid_${most_thread_num_pid} $most_thread_num_pid &exit 0

查看磁盘目录使用情况.sh

#!/bin/bash
#
# Big_Users - find big disk space users in various directories
#############################################################
#Parameters for script
#
CHECK_DIRECTORIES="/var/log /home" #directories to check
#
######################### Main Script #######################
#
DATE=$(date '+%m%d%y')             #Date for report file
#
exec > disk_space_$DATE.rpt         #Make report file Std Output
#
echo "Top Ten Disk Space Usage"     #Report header for while report
echo "for $CHECK_DIRECTORIES Directories"
#
for DIR_CHECK in $CHECK_DIRECTORIES       #loop to du directories
doecho ""echo "The $DIR_CHECK Directory:"	#Title header for each directory
#
#	Creating a listing of top ten disk space usersdu -S $DIR_CHECK 2>/dev/null |sort -rn |sed '{11,$D; =}' |sed 'N; s/\n/ /' | gawk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}'
#
done								#End of for loop for du directories
#

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/751854.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

机器人路径规划:基于改进型A*算法的机器人路径规划(提供Python代码)

一、A*算法介绍 A*算法最早可追溯到1968年&#xff0c;在IEEE Transactions on Systems Science and Cybernetics中的论文A Formal Basis for the Heuristic Determination of Minimum Cost Paths中首次提出。 https://blog.csdn.net/weixin_46204734/article/details/1367905…

C++/CLI学习笔记5(快速打通c++与c#相互调用的桥梁)

3.6 句柄与指针 在标准C中&#xff0c;指针容纳的是另一个变量或函数的内存地址。这意味着可用指针间接引用变量。 但在C/CLI中&#xff0c;是“运行时”帮你管理内存&#xff0c;所以它保留了将内存里的东西移来移去以最大化可用内存的权利。这意味着对象可能不老是呆在一个位…

Windows 网络质量测试

Windows 网络质量测试 References 保证网络稳定性&#xff0c;建议最大数据包延迟 200ms 以内&#xff0c;数据包最大和最小延迟差 100ms 以内&#xff0c;丢包率最好不丢包或 5% 以内。 ping www.baidu.com -t 调出 运行 (快捷键 Win R)&#xff0c;输入 cmd&#xff0c;pi…

安全地使用v-html

vue2 1、 使用插件DOMPurify DOMPurify是一个开源的基于DOM的快速XSS净化工具。输入HTML元素,然后通过DOM解析递归元素节点,进行净化,输出安全的HTML <div v-html"sanitizedContent"></div>import DOMPurify from dompurify; data () {return {htmlCont…

黑马程序员——javase进阶——day08——异常,多线程,Lambda,Stream,File,递归

目录&#xff1a; 异常的概述 什么是异常异常的存在的形式程序中异常产生后&#xff0c;是如何处理的异常的分类异常的处理方式 JVM处理异常的方式手动处理异常方式 声明异常抛出异常捕获异常Throwable的成员方法异常练习自定义异常 概述实现步骤自定义异常注意多线程入门 多线…

文献阅读笔记:SAM大模型(Segment Anything)

文献阅读笔记&#xff1a;SAM大模型&#xff08;Segment Anything&#xff09; 摘要Abstract1. SAM大模型1.1 文献摘要1.2 引言1.3 SAM大模型网络结构1.4 实验1.4.1 零样本单点有效掩码评估1.4.2 零样本边缘检测1.4.3 零样本对象提议1.4.4 零样本通过文本提示预测mask 1.5 SAM模…

双向链表的实现

带头双向循环链表 1. 项目头文件2. 具体实现功能2.1 双向链表的初始化2.2 双向链表尾插2.3 双向链表头插2.4 双向链表尾删2.5 双向链表头删2.6 双向链表查找2.7 双向链表在pos的前面进行插入2.8 双向链表删除pos位置的节点2.9 双向链表打印2.10 双向链表销毁 我们上篇博客进行了…

27-2 文件上传漏洞 - 前端绕过

环境准备:构建完善的安全渗透测试环境:推荐工具、资源和下载链接_渗透测试靶机下载-CSDN博客 前端绕过思路 - 禁用 JavaScript: 背景: 当前开发行业大多采用前后端分离模式,后端使用多种开发语言如 PHP、Java 等,而前端主要使用 JavaScript(JS)。因此,禁用 JavaScrip…

基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的火焰与烟雾检测系统详解(深度学习模型+UI界面升级版+训练数据集)

摘要&#xff1a;本研究详细介绍了一种集成了最新YOLOv8算法的火焰与烟雾检测系统&#xff0c;并与YOLOv7、YOLOv6、YOLOv5等早期算法进行性能评估对比。该系统能够在包括图像、视频文件、实时视频流及批量文件中准确识别火焰与烟雾。文章深入探讨了YOLOv8算法的原理&#xff0…

Django实现登录注册

Django实现登录注册 目录 Django实现登录注册配置路由首页注册前端&#xff1a;后端&#xff1a; 登录前端&#xff1a;后端&#xff1a;验证码部分逻辑 配置路由 首先分发路由[User,Blog,Article] from django.contrib import admin from django.urls import path from Blog…

深度学习——yolov5的txt和xml互转

在学习工作的过程中&#xff0c;有时会需要自己新建数据集&#xff0c;向训练数据中添加新的数据&#xff0c;存在已有模型对新数据进行检测&#xff0c;得到yolov5对应的txt文件&#xff0c;之后转成xml&#xff0c;使用标注工具对数据进行校正。后续将xml转成yolov5训练使用的…

误删电脑C盘要重装系统吗 误删电脑C盘文件怎么恢复 误删c盘系统文件怎么修复 不小心删除C盘的东西恢复

C盘通常是操作系统(如Windows)的默认安装目录。它包含了操作系统的核心文件、驱动程序及系统所需的各种支持文件。这些文件对于计算机的正常运行至关重要。如果我们不小心将C盘的重要文件删除&#xff0c;会导致应用无法打开。本篇文章&#xff0c;我们将学习误删电脑C盘要重装…

面试算法-39-删除链表的倒数第 N 个结点

题目 给你一个链表&#xff0c;删除链表的倒数第 n 个结点&#xff0c;并且返回链表的头结点。 示例 1&#xff1a; 输入&#xff1a;head [1,2,3,4,5], n 2 输出&#xff1a;[1,2,3,5] 解 class Solution {public ListNode removeNthFromEnd(ListNode head, int n) {L…

基于支持向量机SVM的沉降预测,SVM详细原理,Libsvm详解

目录 支持向量机SVM的详细原理 SVM的定义 SVM理论 Libsvm工具箱详解 简介 参数说明 易错及常见问题 完整代码和数据下载链接:基于支持向量机SVM的沉降预测资源-CSDN文库 https://download.csdn.net/download/abc991835105/88947544 SVM应用实例,基于支持向量机SVM的沉降预测…

vim,gcc,gdb与Makefile的使用

一、Linux编辑器-vim使用 1.vim的基本概念 vim的三种模式(其实有好多模式&#xff0c;目前掌握这3种即可),分别是命令模式&#xff08;command mode&#xff09;、插入模式&#xff08;Insert mode&#xff09;和底行模式&#xff08;last line mode&#xff09;&#xff0c;…

指挥航空公司架次与延误率占比

打开前端Vue项目kongguan_web&#xff0c;创建前端 src/components/Delay.vue 页面&#xff0c;并添加柱状图与折线图叠加&#xff0c;设置双Y轴。 页面div设计&#xff0c;代码如下&#xff1a; <template><div><div class"home"><div id&qu…

AJAX-XMLHttpRequest

XMLHttpRequest 定义&#xff1a; XMLHttpRequest对象用于与服务器交互。通过XMLHttpRequest可以在不断刷新页面的情况下请求特定URL&#xff0c;获取数据。这允许网页在不影响用户操作的情况下&#xff0c;更新页面的局部内容。 关系&#xff1a; axios内部采用XMLHttpReques…

关于volatile与指令重排序的探讨

写在开头 在之前的学习我们了解到&#xff0c;为了充分利用缓存&#xff0c;提高程序的执行速度&#xff0c;编译器在底层执行的时候&#xff0c;会进行指令重排序的优化操作&#xff0c;但这种优化&#xff0c;在有些时候会带来 有序性 的问题。 那何为有序性呢&#xff1f;…

乘积尾零啊填空题)

乘积尾零 题目描述 本题为填空题&#xff0c;只需要算出结果后&#xff0c;在代码中使用输出语句将所填结果输出即可。 如下的 10 行数据&#xff0c;每行有 10 个整数&#xff0c;请你求出它们的乘积的末尾有多少个零? 的乘积的末尾有多少个零? 5650 4542 3554 473 946 4…

Halcon OCR文字识别

1、OCR文字识别 OCR&#xff08;Optical Character Recognition&#xff0c;光学字符识别&#xff09;工具对图像中的文字进行识别和分析。 FontFile : Universal_0-9_NoRej dev_update_window (off) read_image (bottle, bottle2) get_image_size (bottle, Width, Height) dev…