有两个问题:
我需要从bash脚本中发送电子邮件,但不能使用sendmail。已安装PHP,并且MTA在本地主机(127.0.0.1)上运行,因此我正在考虑将电子邮件发送到127.0.0.1:25。
实现此目标的最佳做法是什么?
作为最后的选择,我也许可以在Python或Perl中实现它。 但是,目标是在不安装太多额外软件包的情况下实现它。
我将附上我到目前为止所取得的成就:
#!/bin/bash
#check website for changes
#v1.0
#this script requires the stylesheet "generate_ips.xslt" to reside in the
#same directory as this script
#the stylesheet will print the country name and the ips with a line feed
#character after them by accessing them via their xpath
#logfiles are saved in the directory from which this script is run
echo "This script will check the following websites for changes"
echo "1. APAC"
echo "2. AMERICAS"
echo "3. EMEA"
read -p "Press enter to continue"
echo -ne '##### (33%)\r'
sleep 1
URL1="https://support.symantec.com/en_US/article.TECH244698.html" #APAC
URL2="https://support.symantec.com/en_US/article.TECH243000.html" #AMERICAS
URL3="https://support.symantec.com/en_US/article.TECH244697.html" #EMEA
DATE=$(date +"%Y%m%d") #defines the date which is used in the logfile name
#This processes the 3 URLs from above, awk extracts the tables and creates
#a simplified html file with only the ip tables.
#XSLT processor produces the output and sed will remove lines that are not
#required
export https_proxy=https://username:password@111.222.111.122:1234
#All connections hereafter use this proxy until line 'unset HTTPS_PROXY' is
#reached
#Proxy is set as: https://LDAP:PW@IPorHOSTNAME:PORT
curl --silent "$URL1" |\
awk 'BEGIN{print "<html><body>"}/<table/{a=1;}/<\/table>/{print;a=0}{if(a)
print;}END{print "</body></html>"}' |\
xsltproc -html generate_ips.xslt - | sed '/^Egress/{d};s/^ *//' >
logfiles/new/APAC_$DATE.log
curl --silent "$URL1" > HTML_APAC_$DATE.log #Gets URL1 (APAC) as HTML file
#and saves it to specified filename
curl --silent "$URL2" |\
awk 'BEGIN{print "<html><body>"}/<table/{a=1;}/<\/table>/{print;a=0}{if(a)
print;}END{print "</body></html>"}' |\
xsltproc -html generate_ips.xslt - | sed '/^Egress/{d};s/^ *//' >
logfiles/new/AMERICAS_$DATE.log
curl --silent "$URL2" > HTML_AMERICAS_$DATE.log #Gets URL2 (AMERICAS) as
#HTML file and saves it to specified filename
echo -ne '############# (66%)\r'
sleep 1
curl --silent "$URL3" |\
awk 'BEGIN{print "<html><body>"}/<table/{a=1;}/<\/table>/{print;a=0}{if(a)
print;}END{print "</body></html>"}' |\
xsltproc -html generate_ips.xslt - | sed '/^Egress/{d};s/^ *//' >
logfiles/new/EMEA_$DATE.log
curl --silent "$URL3" > HTML_EMEA_$DATE.log #Gets URL3 (EMEA) as HTML file
#and saves it to specified filename
sleep 1 #Wait for 1sec
unset HTTPS_PROXY #Disables proxy
echo -ne '####################### (100%)\r'
echo -ne '\n'
sleep 1
exit 0; #Finish