脚本赋予执行权限

[root@VM_0_10_centos shellScript]# chmod a+x checkRoot.sh 
[root@VM_0_10_centos shellScript]# ./checkRoot.sh 

脚本内容

#!/bin/bash
# 前者使用字串对比,后者使用UID数字对比
# 检测本机当前用户是否为超级管理员,如果是管理员则使用yum安装vsftpd;如果不是,则提示非管理员权限
if [ $USER == "root" -o $UID -eq 0 ];
then
    yum -y install vsftpd
else
    echo "您不是管理员,没有权限安装软件"
fi

PS:注意vsftpd默认宿主用户为root

 

相关文章:

  • 2021-06-11
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-06-23
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-26
  • 2021-10-22
相关资源
相似解决方案