#!/bin/bash
 #
 #Delete_user - Automates the  steps to remove an account
 #
 ###############################################################
 #Define Functions
 #
 ###############################################################
 function get_answer {
 #
 unset ANSWER
 ASK_COUNT=
 #
 while [ -z "$ANSWER" ]    #While no answer is given,keeping asking......
 do
 ASK_COUNT=$[ $ASK_COUNT +  ]
 #
 case $ASK_COUNT in #If user gives no answer in time allotted
 )
 echo
 echo "Please answer the question."
 echo
 ;;
 )
 echo
 echo "One last try...please answer the question."
 echo
 ;;
 )
 echo
 echo "Since you refuse to answer the question..."
 echo "exiting program."
 #
 exit
 ;;
 esac
 #
 echo
 #
 if [ -n "$LINE2" ]
  lines
 echo "$LINE1"
 echo -e $LINE2"\c"    # "-e" Deal with paticualar character,'\c' is oppsite with '\n'.
  line
 echo -e $LINE1"\c"
 fi
 #
 #    Allow  seconds to answer before time-out
 read -t  ANSWER
 done
 #Do a little variable clean-up
 unset LINE1
 unset LINE2
 #
 }    #End of get_answer function.
 #
 ##########################################################################
 function process_answer {
 #
 unset ANSWER
 echo "process_answer[y/n]?"
 read -t  ANSWER
 case $ANSWER in
 y|Y|YES|yes|yEs|yeS|YEs|yES|Yes|YeS)
 #If user answer "yes" ,do nothing.
 ;;
 *)
 #If user answers anything but "yes",exit script
 echo
 echo $EXIT_LINE1
 echo $EXIT_LINE2
 echo
 exit
 ;;
 esac
 #
 #Do a little variable clean-up
 #
 unset EXIT_LINE1
 unset EXIT_LINE2
 #
 }    ##End of process_answer function
 #
 #
 #########################################################################
 #End of Function Definitions    #
 #    #
 #########################################################################
 #    #
 #    #
 ############# Mani Scripts ##############################################
 #    #
 #    #
 #    #
 #########################################################################
 #
 ##Get name of User Accout to check
 #
 echo "Step #1 - Determine User Accout 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
 #
 #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_answer
 #
 ############################################################################
 #Check that USER_ACCOUNT is really an account on the system
 #
 USER_ACCOUNT_RECORD=$(cat /etc/passwd | grep -w $USER_ACCOUNT)
 #
  ] #If the account is not found,exit script.
 then
 echo
 echo "Account ,$USER_ACOUNT,not found."
 echo "leaving the script..."
 echo
 exit
 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 answer 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_answer
 #
 ##############################################################################
 #Search for any running processes that belong to the use 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 user processes running
 case $? in
 )    #No processes running for this user account
 #
 echo "There are no processes for this account currently running."
 echo
 ;;
 )    #processes running for this User Account.
 #Ask Script User if wants us to kill the processes.
 #
 unset ANSWER
 LINE1="Would you like me to kill the processes(es)?[y/n]"
 get_answer
 #
 case $ANSWER in
 y|Y|yes|Yes|yEs|yeS|YEs|YeS|yES|YES)    #if user answer 'yes'.
 #
 echo
 #
 #Clean-up temp file upon signals
 trap "rm $USER_ACCOUNT_Running_Process.rpt" SIGTERM SIGINT SIGQUIT
 #
 #List user processes running
 ps -u $USER_ACCOUNT_Running_Process.rpt
 #
 exec < $USER_ACCOUNT_Runnning_Process.rpt    #make report Std Input
 #
 read USER_PROCESS_REC    #First record will be blank
 read USER_PROCESS_REC
 #
  ]
 do
 #obtain PID
 USER_PID=$(echo $USER_PROCESS_REC | cut -d " " -f1)    # output a line of characters,'cut -d "," -f2' will select second
 # part which splited by ",".Is same to" gawk '{print $2}' ".
  $USER_PID
 echo "Killed process $USER_PID"
 read USER_PROCESS_REC
 done
 #
 echo
 rm $USER_ACCOUNT_Running_Process.rpt # Remove temp report
 ;;
 *)    #If user answers anything but "yes",do not kill
 echo
 echo "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"
 #
 #
 >/dev/null    # How to use "find"
 #    #There don't deal with $USER's file.
 echo
 echo "Report is conplete"
 echo "Namp of report:    $REPORT_FILE"
 echo "Location of report:    `pwd`"
 echo
 ############################################################################################
 # Remove User Account
 echo
 echo "Step #4 - Romove user account"
 echo
 LINE1="Do you wish to remove $User_Account's account from system?[y/n]"
 get_answer
 #
 # Call process_answer function:
 #    if user answer 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
 #
 #
 #END

manage account的更多相关文章

  1. Web API 入门指南 - 闲话安全

    Web API入门指南有些朋友回复问了些安全方面的问题,安全方面可以写的东西实在太多了,这里尽量围绕着Web API的安全性来展开,介绍一些安全的基本概念,常见安全隐患.相关的防御技巧以及Web AP ...

  2. ASP.NET MVC5 网站开发实践(二) Member区域 - 用户部分(3)修改资料、修改密码

    在上一篇博客中实现了用户的注销和登录,其实代码里落了点东西,就是用户登录要更新最后一次登录时间和登录IP,这次补上.今天做修改资料和修改密码,TryUpdateModel是新用到的东西. 目录: AS ...

  3. [.NET领域驱动设计实战系列]专题七:DDD实践案例:引入事件驱动与中间件机制来实现后台管理功能

    一.引言 在当前的电子商务平台中,用户下完订单之后,然后店家会在后台看到客户下的订单,然后店家可以对客户的订单进行发货操作.此时客户会在自己的订单状态看到店家已经发货.从上面的业务逻辑可以看出,当用户 ...

  4. Web API 使用上安全吗?

    Web API入门指南有些朋友回复问了些安全方面的问题,安全方面可以写的东西实在太多了,这里尽量围绕着Web API的安全性来展开,介绍一些安全的基本概念,常见安全隐患.相关的防御技巧以及Web AP ...

  5. 【转】20个Cydia常见错误问题解决方法汇总

    对于已经越狱的用户来说,经常会使用Cydia来安装一些酷炫或实用插件,但是有时候它总是会出现一些问题,以下收集了在Cydia经常遇到的问题,供大家参考: 一.主屏幕没有 Cydia 图标 1.设备需已 ...

  6. 定制Asp.NET 5 MVC内建身份验证机制 - 基于自建SQL Server用户/角色数据表的表单身份验证

    背景 在需要进行表单认证的Asp.NET 5 MVC项目被创建后,往往需要根据项目的实际需求做一系列的工作对MVC 5内建的身份验证机制(Asp.NET Identity)进行扩展和定制: Asp.N ...

  7. Web API 安全问题

    目录 Web API 安全概览 安全隐患 1. 注入(Injection) 2. 无效认证和Session管理方式(Broken Authentication and Session Manageme ...

  8. Web API 入门指南 - 闲话安全(转)

    Web API 安全概览 安全隐患 1. 注入(Injection) 2. 无效认证和Session管理方式(Broken Authentication and Session Management) ...

  9. Web API入门指南(安全)转

    安全检测的工具站点:https://www.owasp.org/index.php/Category:Vulnerability_Scanning_Tools Web API入门指南有些朋友回复问了些 ...

随机推荐

  1. isNaN() 确认是否是数字

    isNaN(x): 当变量 x 不是数字,返回 true: 当变量 x 是其他值,(比如,1,2,3),返回false.

  2. CSS样式案例(1)-文字的排版

    本篇介绍的是小窗文字内容的排版,通过该篇文章可以让小伙伴们熟悉以下几个知识点: word-space.overflow.text-overflow. 最终的展示效果如下: 参考步骤: 1. 建立htm ...

  3. JAVA 笔记

    一.Java基础以及面向对象编程1.float类型的数自动转换成double类型时,可能会出现前后不相等的情况,因为有些数不能够用有限的二进制位精确表示.2.右移>>右移,左边空出位以符号 ...

  4. linux 模块加载

    错误: rmmod 时提示 rmmod: chdir(xxx): No such file or directory 解决方法: http://blog.csdn.net/luckywang1103/ ...

  5. 4. Linux常用命令

    1. ls  查看当前目录信息 2. pwd 查看当前目录 3. cd 切换目录  快捷操作:cd - 可快速对最近的两个目录切换, cd 或者cd~ 直接回到用户自己的主目录, 4. hwclock ...

  6. HDU 3351 Seinfeld(括号匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3351 解题报告:输入一个只有'{'跟'}'的字符串,有两种操作,一种是把'{'变成'}',另一种是'} ...

  7. [Asp.net MVC]Asp.net MVC5系列——添加模型

    目录 概述 添加模型 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5系列——添加视图 概述 在本节中我们将追加 ...

  8. 小米手机无法打开程序报错Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication的解决办法

    打开studio的setting 然后 Preferences -> Build, Execution, Deployment -> Instant Run -> Enable In ...

  9. 我所理解的cocos2dx自适配屏幕大小方案

    这里主要有两个点: 1.屏幕大小的设置,也就是手机窗口的大小,在各个手机上面或者平板上的屏幕的大小. 这个大小的设置就是代码里面的:glview->setFrameSize(width, hig ...

  10. [hihoCoder#1065]全图传送

    [hihoCoder#1065]全图传送 试题描述 先知法里奥是 Dota 系列中的一个英雄.机动性强,推塔能力一流,打钱速度快,传送技能使先知可以全地图支援.在后期比拼中通过强大的兵线控制能力使得对 ...