写一个linux的shell脚本,自动分辨操作系统区别,在centos操作系统下执行yum install -y libpcap libpcap-devel file-libs pcre-devel pcre libyaml-devel libyaml libcap-ng-devel libcap-ng jansson jansson-devel,在其他操作系统下执行apt install -y libpcap libpcap-dev file-libs pcre-dev pcre libyaml-dev libyaml libcap-ng-dev libcap-ng jansson jansson-de
时间: 2024-01-07 20:05:22 浏览: 132
以下是一个自动分辨操作系统并执行相应命令的shell脚本:
```bash
#!/bin/bash
# 检查操作系统类型
if [[ $(uname -s) == "Linux" ]]; then
if [[ -f /etc/os-release ]]; then
. /etc/os-release
OS=$ID
else
OS=$(uname -s)
fi
else
echo "该脚本只能在Linux系统上运行!"
exit 1
fi
# 根据操作系统类型执行相应命令
if [[ $OS == "centos" ]]; then
yum install -y libpcap libpcap-devel file-libs pcre-devel pcre libyaml-devel libyaml libcap-ng-devel libcap-ng jansson jansson-devel
elif [[ $OS == "ubuntu" || $OS == "debian" ]]; then
apt install -y libpcap libpcap-dev file-libs pcre-dev pcre libyaml-dev libyaml libcap-ng-dev libcap-ng jansson jansson-dev
else
echo "不支持的操作系统类型:$OS"
exit 1
fi
```
该脚本会在执行时自动检测操作系统类型,并根据类型执行相应的安装命令。如果检测到的操作系统类型不是CentOS、Ubuntu或Debian,则会提示不支持的操作系统类型并退出。
阅读全文