shell脚本:
#!/bin/bash
if [ $USER == "root" ];then
yum -y install vsftpd
else
echo "You are not root account,installing software is not needed."
fi
OR
#!/bin/bash
if [ $UID -eq 0 ];then
yum -y install vsftpd
else
echo "You are not root account,installing software is not needed."
fi
shell脚本运行:
root-1.sh
[root@elasticsearch ~]# sh root-1.sh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
CentOS7 | 3.6 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-28.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
vsftpd x86_64 3.0.2-28.el7 CentOS7 172 k
Transaction Summary
===========================================================================================================
Install 1 Package
Total download size: 172 k
Installed size: 353 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : vsftpd-3.0.2-28.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-28.el7.x86_64 1/1
Installed:
vsftpd.x86_64 0:3.0.2-28.el7
Complete!
[root@elasticsearch ~]#
root-2.sh
[root@elasticsearch ~]# sh root-2.sh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-28.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
vsftpd x86_64 3.0.2-28.el7 CentOS7 172 k
Transaction Summary
===========================================================================================================
Install 1 Package
Total download size: 172 k
Installed size: 353 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : vsftpd-3.0.2-28.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-28.el7.x86_64 1/1
Installed:
vsftpd.x86_64 0:3.0.2-28.el7
Complete!
[root@elasticsearch ~]#