VMware Tools工具安装脚本(CentOS & Ubuntu)

1、VMware Tools(CentOS版)

bash 复制代码
#!/bin/bash

log_info() {
echo "[INFO] $1"
echo "[INFO] $1" >> "$LOGFILE"
}

log_error() {
echo "[ERROR] $1"
echo "[ERROR] $1" >> "$LOGFILE"
exit 1
}

# log to record install process
LOGFILE="/var/log/env-script.log"

mkdir -p /mnt/cdrom || log_error "Failed to create mount point"

chmod 777 /dev/sr0 || log_error "Failed to set CD-ROM permissions"

mount -t iso9660 /dev/sr0 /mnt/cdrom || log_error "Failed to mount ISO image"

cp /mnt/cdrom/VMwareTools-10.3.25-20206839.tar.gz /usr/local/src || log_error "Failed to copy VMware Tools package"

cd /usr/local/src || log_error "Cannot enter extraction directory"
tar -xf VMwareTools-10.3.25-20206839.tar.gz || log_error "Failed to extract VMware Tools package"

cd vmware-tools-distrib || log_error "Cannot enter vmware-tools-distrib directory"

yum install -y perl || log_error "Failed to install Perl dependency"

echo -e "y\n" | ./vmware-install.pl || log_error "Failed to execute VMware Tools installation script"

chmod 660 /dev/sr0 || log_error "Failed to reset CD-ROM permissions"

# recoard success information
log_info "All steps completed."
echo "All steps completed." >> "$LOGFILE"

2、VMware Tools(Ubuntu版)

bash 复制代码
#!/bin/bash

log_info() {
echo "[INFO] $1"
echo "[INFO] $1" >> "$LOGFILE"
}

log_error() {
echo "[ERROR] $1"
echo "[ERROR] $1" >> "$LOGFILE"
exit 1
}

# Log file to record install process
LOGFILE="/var/log/env-script.log"

# Create mount point if it doesn't exist
mkdir -p /mnt/cdrom || log_error "Failed to create mount point"

# Set CD-ROM permissions
chmod 777 /dev/cdrom || log_error "Failed to set CD-ROM permissions"

# Mount the ISO image
mount -t iso9660 /dev/cdrom /mnt/cdrom || log_error "Failed to mount ISO image"

# Copy VMware Tools package
cp /mnt/cdrom/VMwareTools-10.3.25-20206839.tar.gz /usr/local/src || log_error "Failed to copy VMware Tools package"

# Change to the extraction directory
cd /usr/local/src || log_error "Cannot enter extraction directory"

# Extract VMware Tools package
tar -xf VMwareTools-10.3.25-20206839.tar.gz || log_error "Failed to extract VMware Tools package"

# Change to the extracted directory
cd vmware-tools-distrib || log_error "Cannot enter vmware-tools-distrib directory"

# Install Perl dependency
apt-get update || log_error "Failed to update package list"
apt-get install -y perl || log_error "Failed to install Perl dependency"

# Execute VMware Tools installation script
echo -e "y\n" | ./vmware-install.pl || log_error "Failed to execute VMware Tools installation script"

# Reset CD-ROM permissions
chmod 660 /dev/cdrom || log_error "Failed to reset CD-ROM permissions"

# Record success information
log_info "All steps completed."
echo "All steps completed." >> "$LOGFILE"
相关推荐
VinciYan29 分钟前
基于Jenkins+Docker的自动化部署实践——整合Git与Python脚本实现远程部署
python·ubuntu·docker·自动化·jenkins·.net·运维开发
州周31 分钟前
Ftp目录整个下载
linux·服务器·数据库
Jackey_Song_Odd32 分钟前
Ubuntu 24.04.1 解决部分中文字符(门、径)显示错误的问题
linux·ubuntu
kaixin_learn_qt_ing44 分钟前
Linux export命令
linux
余额不足121381 小时前
C语言基础十六:枚举、c语言中文件的读写操作
linux·c语言·算法
冷曦_sole1 小时前
linux-19 根文件系统(一)
linux·运维·服务器
AI大模型学徒1 小时前
Linux(二)_清理空间
linux·运维·服务器
云川之下1 小时前
【linux】 unshare -user -r /bin/bash命令详解
linux·bash·unshare
tntlbb1 小时前
Ubuntu20.4 VPN+Docker代理配置
运维·ubuntu·docker·容器
热心市民运维小孙1 小时前
Ubuntu重命名默认账户
linux·ubuntu·excel