Chinaunix首页 | 论坛 | 博客
  • 博客访问: 101162899
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: C/C++

2008-03-26 19:25:29

作者:DRAGON_nx   
新建用户SHUT,组名为SYS
shut.c源码*/
#include 
#include 
main()
{
setuid(0);
setgid(3);
system("/etc/shutdown -y -g0");
}
/*将shut文件拷贝到shut目录*/
chown root shut
chgrp sys shut
chmod 4710 shut
vi .profile
-o
./shut
/*修改.profile文件*/
:
#      @(#) profile 68.1 98/01/20 
#
#      Copyright (C) 1989-1998 The Santa Cruz Operation, Inc.
#            All Rights Reserved.
#      The information in this file is provided for the exclusive use of
#      the licensees of The Santa Cruz Operation, Inc.  Such users have the
#      right to use, modify, and incorporate this code into other products
#      for purposes authorized by the license agreement provided they include
#      this notice and the associated copyright notice with any such product.
#      The information in this file is provided "AS IS" without warranty.
#
# .profile      -- Commands executed by a login Bourne shell
#
trap "exit" 0 1 2 3 4 5 6 7 8 9 10 0A 0B 0C 0D 15
PATH=$PATH:$HOME/bin:.                  # set command search path
MAIL=/usr/spool/mail/`logname`            # mailbox location
export PATH MAIL
TERM=ansi;export TERM
/usr/bin/prwarn                  # issue a warning if password due to expire
#===========================================================================#
welcome()
{
   while true
   do
      clear
      echo "\n\n\n\n\n"
      echo "\t\t┏━━━━━━━━━━━━━━━━━━━━━━━┓"
      echo "\t\t┃                 [ 关机程序 ]                 ┃"
      echo "\t\t┃                                              ┃"
      echo "\t\t┃  本程序用于安全地关闭计算机,请在日终后执行。┃"
      echo "\t\t┃                                              ┃"
      echo "\t\t┗━━━━━━━━━━━━━━━━━━━━━━━┛"
      echo "\n\t\t  继续吗(y/n)? \c"
      read YN
      [ ! "$YN" ] && continue
      [ $YN = "Y" -o $YN = "y" -o $YN = "1" ] && break
      [ $YN = "N" -o $YN = "n" -o $YN = "0" ] && clear && exit
   done
}
#===========================================================================#
wall()
{
while true
do
     clear
     echo "\n请输入关机时间(分钟): \c"
     read Min
     Min=`echo $Min|awk '$1>0 && $1<60 { printf("%d",$1) }'`
     Min=`echo $Min|awk '$1>0 && $1<60 {
         if ( $1 >0 && $1 <10 )
            $1 = " "$1
         print $1 }'`
     [ ! "$Min" ] && continue
     break
done
for TTYS in `who | awk '{ print $2 }'`
do
     echo >/dev/$TTYS
     cat </dev/$TTYS
┏━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                [ 来自主机的消息 ]                ┃
┃                                                  ┃
┃  主机将在$Min分钟内关机,请尽快完成业务,关闭终端。┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━┛
!
done
echo "\n上述信息已经发往各终端,按任意键继续...\c"
read Key
}
#===========================================================================#
exam()
{
     clear
     Users=`who|wc -l`
     while [ $Users -gt 1 ]
     do
           clear
           Cttys=`who -m | awk '{ print $2 }'`
           echo "        下列终端尚未退出∶\n"
           echo "\t登录名  终端号  开始时间  电话号码  单 位 名 称"
           echo "\t==============================================="
           i=1
           while [ $i -le $Users ]
           do
                 User=`who | awk 'NR == '$i' { print $1 }'`
                 TermID=`who | awk 'NR == '$i' { print $2 }'`
                 Time=`who | awk 'NR == '$i' { print $5 }'`
                 TelNu=`cat TtyParameter | awk ' $1 == "'$TermID'" { print $2 }'`
                 Name=`cat TtyParameter | awk ' $1 == "'$TermID'" { print $3 }'`
                 if [ $TermID != $Cttys ]
                 then
                    echo "\t$User    $TermID   $Time     $TelNu   $Name"
                 fi
                 i=`expr $i + 1`
           done
           echo 
           echo "\t┏━━━━━━━━━━━━━━━━┓"
           echo "\t┃ 1) 重 新 测 试                 ┃"
           echo "\t┃ 2) 向未退出的终端发送关机信息  ┃"
           echo "\t┃ 3) 强 行 关 机                 ┃"
           echo "\t┃ 0) 退       出                 ┃"
           echo "\t┗━━━━━━━━━━━━━━━━┛"
           echo "\t 请选择[1]: \c"
           read sele
           case $sele in
                2) wall;;
                  3) break;;
                    0) clear;exit;;
                    *) ;
           esac
           Users=`who|wc -l`
     done
     echo "\n\t所有用户都已退出,开始关闭系统...\c"
     haltsys
}
#===========================================================================#
main()
{
     clear
     if [ `tty` != "/dev/tty01" ]
     then
           echo "\n\t请在主机第一屏关机!\n"
           exit
     fi
     while [ `cat ./TtyParameter | wc -l` = "3" ]
     do
           clear
           echo "\n按Enter键向${HOME}/TtyParameter中添加网点终端的信息."
           echo "\n按Del键盘退出...\c"
           read Key
           vi ./TtyParameter
     done
     welcome
     exam
     exit
}            
#===========================================================================#
main
阅读(434) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~