У меня есть скрипт speedtest, который я написал в Bash для MacOS, использующий утилиту Ooklas Speedtest Cli, которая отлично работает при запуске вручную, но когда я устанавливаю свой crontab, он не записывает в файл журнала в Users / Shared, хотя он создает файл журнала. Я считаю, что моя вкладка cron верна. Я использую сторонний спидтест и бинарный gsed, не родной для MacOS, это может быть проблемой? Похоже, он обходит команды speedtest | gsed -r 's/.* ([0-9]+\.*[0-9]*).*?/\1/'
и просто создает файл. Может ли cron сделать что-то другое, чем запускать скрипт вручную?
Любой совет будет БОЛЬШОЙ оценен, и я прошу прощения за неряшливость!
#this script runs a speedtest from a server and emails sysadmins if the download, upload, or latency
#reaches a certain threshold
#!/bin/bash
#insturctions
#install home brew; install speedtest cli; install mailutlis if necessary; configure postfix
#install gsed
#brew install gnu-sed
#debugging
#set -x
#network variables
expected_upload=5.00
expected_download=10.00
expected_latency=50.00
today=$(date +"%Y-%m-%d_%H-%M")
echo about to run speedtest
#formatting document
speedtest | gsed -r 's/.* ([0-9]+\.*[0-9]*).*?/\1/' > /Users/Shared/speedtest_logs/$today.txt
echo finished running speedtest
echo assigning variables from results
#variables are pulled from speedtest
latency=$(awk 'FNR == 6 { print $1}' /Users/Shared/speedtest_logs/$today.txt)
download=$(awk 'FNR == 7 { print $1}' /Users/Shared/speedtest_logs/$today.txt)
upload=$(awk 'FNR == 8 { print $1}' /Users/Shared/speedtest_logs/$today.txt)
echo $HOSTNAME current upload speed is $upload
echo $HOSTNAME current download speed is $download
echo $HOSTNAME latency to the speedtest server is $latency
#determining if your download speed is lower than expected
if (( $(echo "$download < $expected_download" |bc -l) )); then
echo download speed below expected theshold of 10 mbps - investigate
#insert email trigger
mail -s "WARNING DEPRICATED DOWNLOAD AT $HOSTNAME" test@gmail.com <<EOF
Current download speed at $HOSTNAME is "$download"mbps
EOF
# WHEN USING SSMTP echo -e "Subject:Depricated Download Speed\ncurrent download speed currently $download mbps"| /usr/sbin/ssmtp test@gmail.com
else echo download speeds are normal
fi
#determining if your upload speed is lower than expected
if (( $(echo "$upload < $expected_upload" |bc -l) )); then
echo upload speed below expected theshold of 5 mbps - investigate
#insert email trigger
mail -s "WARNING DEPRICATED UPLOAD AT $HOSTNAME" test@gmail.com <<EOF
Current upload speed at $HOSTNAME is "$upload"mbps
EOF
#WHEN USING SSMTP echo -e "Subject:Depricated upload Speed\ncurrent upload speed currently $upload mbps"| /usr/sbin/ssmtp test@gmail.com
else echo upload speeds are normal
fi
#determining if your latency is within your defined threshold of < 50ms
if (( $(echo "$latency > $expected_latency" |bc -l) )); then
echo latency to speedtest server is high - investigate
#insert email trigger
mail -s "WARNING INCREASED LATENCY AT $HOSTNAME" test@gmail.com <<EOF
Current latency for $HOSTNAME is "$latency"ms
EOF
#WHEN USING SSMTP echo -e "Subject:High Latency\ncurrent latency $latency ms"| /usr/sbin/ssmtp test@gmail.com
else echo latency is within the normal threshold
fi