我设法创建了一个工作脚本来从我有会员资格的受登录保护的网站收集信息,我希望该脚本可以在 cronjob 上运行,但它没有。
我在这里做错了什么吗?
#!/bin/bash
COOKIES="kukis.txt"
curl -k -c $COOKIES --data "userid=$(sed -n 1p /home/reza/Videos/.ktsandi.txt)&pass=$(sed -n 2p /home/reza/Videos/.ktsandi.txt)" https://my.smartfren.com/mysmartfren_login/login
LOG="frenlog.html"
until curl 'https://my.smartfren.com/mysmartfren_home'-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/72.0.3626.121 Chrome/72.0.3626.121 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://my.smartfren.com/mysmartfren_login' -H 'Connection: keep-alive' -b $COOKIES -H 'Upgrade-Insecure-Requests: 1' -H 'Cache-Control: max-age=0' &> /dev/stdout | tee -a $LOG
do
echo "$(date '+%d/%m/%Y') - Failed to run, will retry shortly" >> /home/reza/testfren/skrip.log
done && rm /home/reza/testfren/${COOKIES}
# EMAIL DATA
RECIPIENT="[email protected]"
MAILER="[email protected]"
SUBJECT="Info kuota harian Smartfren"
# SORTING...
MAIL="frendata.html"
expDateBonus="16/04/2019 23:59:58"
expDate="05/05/2019 23:59:58"
if [[ $(date "+%d/%m/%Y %H:%M:%S") == $expDateBonus ]] || [[ $(date "+%d/%m/%Y %H:%M:%S") == $expDate ]]
then
grep -A1 -E "<tr><td width='40%'>Bonus Data</td><td>|<tr><td width='40%'>Midnight Internet</td><td>" $LOG | sed "/--/d" | sed -n '3,4p;7,8p' >> $MAIL
else
grep -A1 -E "<tr><td width='40%'>Bonus Data</td><td>|<tr><td width='40%'>Midnight Internet</td><td>" $LOG | sed "/--/d" >> $MAIL
fi
#SENDING MAIL
(
echo To: $RECIPIENT
echo From: $MAILER
echo "Content-Type: text/html; "
echo Subject: $SUBJECT
echo Remaining internet quota as of $(date "+%d/%m/%Y")
echo
cat $MAIL
) | sendmail -t && rm $MAIL $LOG
答案1
首先,最好使用完整路径等curl
,sendmail
以确保您可以访问命令。其次,最好获取您的 bash 配置文件:
source /path/to/your/home/.bashrc
或者
. /path/to/your/home/.bashrc
并在之后添加
#!/bin/bash