日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux shell脚本 wget,bash – 在shell脚本中运行wget和其他命令

發布時間:2025/4/5 linux 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux shell脚本 wget,bash – 在shell脚本中运行wget和其他命令 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以下是編寫shell腳本時要使用的一些準則.

>使用它們時始終引用變量.這有助于避免誤解的可能性. (如果文件名包含空格怎么辦?)

>不要相信像rm這樣的命令上的文件加載.請改用循環. (如果文件名以連字符開頭怎么辦?)

>盡可能避免使用子殼.帶反引號的線條讓我發癢.

>如果你能提供幫助,請不要執行.特別是在你的exec實際運行之后,不要指望腳本的任何部分.@H_502_2@

我應該指出,雖然你的shell可能是bash,但你已經指定了/ bin / sh來執行這個腳本,所以它不是一個bash腳本.@H_502_2@

這是一個重寫錯誤檢查.加鹽調味.@H_502_2@#!/bin/sh

# Linux

wget=/usr/bin/wget

tar=/bin/tar

apachectl=/usr/sbin/apache2ctl

# FreeBSD

#wget=/usr/local/bin/wget

#tar=/usr/bin/tar

#apachectl=/usr/local/sbin/apachectl

TXT="GOT TO THE END,YEAH"

WORKING_DIR="/var/asl/updates"

TARGET_DIR="/usr/local/apache/conf/modsec_rules/"

EXISTING_FILES_DIR="/var/asl/updates/modsec/"

EXISTING_ARCH="/var/asl/updates/"

URL_BASE="http://updates.atomicorp.com/channels/rules/subscription"

WGET_OPTS='--user="jim" --password="xxx-yyy-zzz"'

if [ ! -x "$wget" ]; then

echo "ERROR: No wget." >&2

exit 1

elif [ ! -x "$apachectl" ]; then

echo "ERROR: No apachectl." >&2

exit 1

elif [ ! -x "$tar" ]; then

echo "ERROR: Not in Kansas anymore,Toto." >&2

exit 1

fi

# change to working directory and cleanup any downloaded files

# and extracted rules in modsec/ directory

if ! cd "$WORKING_DIR"; then

echo "ERROR: can't access working directory ($WORKING_DIR)" >&2

exit 1

fi

# Delete each file in a loop.

for file in "$EXISTING_FILES_DIR"/* "$EXISTING_ARCH_DIR"/modsec-*; do

rm -f "$file"

done

# Move old VERSION out of the way.

mv VERSION VERSION-$$

# wget1 to download VERSION file (replaces WGET1)

if ! $wget $WGET_OPTS $URL_BASE}/VERSION; then

echo "ERROR: can't get VERSION" >&2

mv VERSION-$$VERSION

exit 1

fi

# get current MODSEC_VERSION from VERSION file and save as variable,# but DON'T blindly trust and run scripts from an external source.

if grep -q '^MODSEC_VERSION=' VERSION; then

TARGET_DATE="`sed -ne '/^MODSEC_VERSION=/{s/^[^=]*=//p;q;}' VERSION`"

echo "Target date: $TARGET_DATE"

fi

# Download current archive (replaces WGET2)

if ! $wget ${WGET_OPTS} "${URL_BASE}/modsec-$TARGET_DATE.tar.gz"; then

echo "ERROR: can't get archive" >&2

mv VERSION-$$VERSION # Do this,don't do this,I don't know your needs.

exit 1

fi

# extract archive

if [ ! -f "$WORKING_DIR/modsec-${TARGET_DATE}.tar.gz" ]; then

echo "ERROR: I'm confused,where's my archive?" >&2

mv VERSION-$$VERSION # Do this,I don't know your needs.

exit 1

fi

tar zxvf "$WORKING_DIR/modsec-${TARGET_DATE}.tar.gz"

for file in "$EXISTING_FILES_DIR"/*; do

cp "$file" "$TARGET_DIR/"

done

# So far so good,so let's restart apache.

if $apachectl configtest; then

if $apachectl restart; then

# Success!

rm -f VERSION-$$

echo "$TXT"

else

echo "ERROR: PANIC! Apache didn't restart. Notify the authorities!" >&2

exit 3

fi

else

echo "ERROR: Apache configs are broken. We're still running,but you'd better fix this ASAP." >&2

exit 2

fi

請注意,雖然我已經將其重寫為更加明智,但仍然有很大的改進空間.@H_502_2@

總結

以上是生活随笔為你收集整理的linux shell脚本 wget,bash – 在shell脚本中运行wget和其他命令的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。