六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 143|回复: 0

linux判断root用户

[复制链接]

升级  82%

51

主题

51

主题

51

主题

秀才

Rank: 2

积分
173
 楼主| 发表于 2013-1-15 01:48:47 | 显示全部楼层 |阅读模式
linux 中,如何判断当前用户是否是root  呢?
判断当前用户是否是root
Shell代码  
#---------------------------- root user check ---------------------start     if [ `id -u` -ne 0 ]; then        echo "Please re-run ${this_file} as root."        exit 1     fi     #---------------------------- root user check ---------------------end         if [ x"$USER" = x"" ];then        if  id |grep "^uid=0(root)">/dev/null ;then            :         else            echo "Please rerun `basename $0` as root ."            exit 1         fi     else        if [ ! x"$USER" = x"root" ];then            echo "Please rerun `basename $0` as root ."            exit 1         fi     fi         #=============== check current user start ================     if [ ! $USER = root  ];then        echo "Please rerun this script as root ."        exit 1     fi     #=============== check current user end ================         #!/bin/sh     if  id |grep "^uid=0(root)">/dev/null ;then        echo is  root     else        echo not  root     fi          check_user(){         if [ $UID -ne 0 ];then            echo "Current user is not ROOT."            echo "Please rerun the installer as Root user."            exit 11         fi     }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表