自学内容网 自学内容网

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

1、VMware Tools(CentOS版)

#!/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版)

#!/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"

原文地址:https://blog.csdn.net/Grits/article/details/143749252

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!