shell脚本编写--自动化安装python
1.python3.7版本
#!/bin/bash # ----------------------------------------------------------------- # -------- 创建日期:2022-02 -------- # -------- 作者:ywjia -------- # -------- 邮箱:duxingren201955@163.com -------- # ------------------------------------------------------------------------------- # 功能介绍:安装python3.7 到目录 /usr/local/python3 # -------环境变量---------------------------------------------------------------- # export PYSPARK_PYTHON=python3 # export PYTHONUNBUFFERED=1 # -------自定义的jar包目录----------------------------------------------------- # /usr/jartest/ jar_path=/usr/jartest/ function Print_info_log() { echo -e "\e[1;35m INFO:$(date "+%Y-%m-%d %H:%M:%S") \e[0m $1." | tee -a /install_all.log } function install_python() { if ! python3 -V &>/dev/null; then Print_info_log "python未安装,开始安装" else Print_info_log "python已安装,即将退出" exit 1 fi Print_info_log "开始安装yum依赖" yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel \
readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel wget &>/install.log yum install libffi-devel -y &>/install.log if ! yum install gcc -y &>/install.log;then Print_info_log "yum 安装依赖gcc等失败,详细日志查看/install.log" exit 2 fi #我下载到内网,提高下载速度。外网下载路径:wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz [ -d Python-3.7.0.tgz ] && rm -rf Python-3.7.0.tgz if ! wget http://192.168.38.38:81/js/Python-3.7.0.tgz &>/dev/null; then Print_info_log "下载失败Python-3.7.0.tgz,稍后尝试" exit 3 fi tar xf Python-3.7.0.tgz cd Python-3.7.0 || exit 4 if ! ./configure --prefix=/usr/local/python3 &>/install.log; then Print_info_log "当前编译python失败,日志查看/install.log" exit 5 fi make &>/dev/null && make install &>/dev/null ln -s /usr/local/python3/bin/python3 /usr/bin/python3 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 } install_python [ "$(grep -c PYSPARK_PYTHON /etc/profile)" -eq 0 ] && echo "export PYSPARK_PYTHON=python3" >>/etc/profile [ "$(grep -c PYTHONUNBUFFERED /etc/profile)" -eq 0 ] && echo "export PYTHONUNBUFFERED=1" >>/etc/profile source /etc/profile [ ! -d "${jar_path}" ] && mkdir -p "${jar_path}"