我有一个bash脚本从Heroku获取信息,以便我可以将我的数据库的一个副本。该脚本在cygwin中正常工作。但是在cron中运行它会停止,因为它使用的shell通过Heroku Toolbelt作为Heroku的身份验证暂停。期望失败,但我不明白为什么
这里是我的crontab:
SHELL=/usr/bin/bash
5 8-18 * * 1-5 /cygdrive/c/Users/sam/work/push_db.sh >>/cygdrive/c/Users/sam/work/output.txt
我已经阅读了谷歌和Cygwin中的手册页想出这个加法:
#!/usr/bin/bash
. /home/sam.walton/.profile
echo $SHELL
curl -H "Accept: application/vnd.heroku+json; version=3" -n https://api.heroku.com/
#. $HOME/.bash_profile
echo `heroku.bat pgbackups:capture --expire`
#spawn heroku.bat pgbackups:capture --expire
expect {
"Email:" { send -- "$($HEROKU_LOGIN)\r"}
"Password (typing will be hidden):" { send -- "$HEROKU_PW\r" }
timeout { echo "timed out during login"; exit 1 }
}
sleep 2
echo "first"
curl -o latest.dump -L "$(heroku.bat pgbackups:url | dos2unix)"
下面是从output.txt的
输出/usr/bin/bash
{
"links":[
{
"rel":"schema",
"href":"https://api.heroku.com/schema"
}
]
}
Enter your Heroku credentials. Email: Password (typing will be hidden): Authentication failed. Enter your Heroku credentials. Email: Password (typing will be hidden): Authentication failed. Enter your Heroku credentials. Email: Password (typing will be hidden): Authentication failed.
正如你所看到的,看起来输出没有得到send命令的结果,因为它是ap梨正在等待。我已经完成了许多有关证书和期望陈述的实验。一切都停在这里。我看过几个例子,并试图尝试这些,但我得到模糊的眼睛,这就是为什么我在这里发布。我不了解什么?
感谢您的意见,我想起明确地把我的ENV变量在.bashrc中:每@迪内希的很好的例子是低于
[[ -s $USERPROFILE/.pik/.pikrc ]] && source "$USERPROFILE/.pik/.pikrc"
export HEROKU_LOGIN=myEmailHere
export HEROKU_PW=myPWhere
我的修订后的脚本:
. /home/sam.walton/.bashrc echo $SHELL echo $HEROKU_LOGIN curl -H "Accept: application/vnd.heroku+json; version=3" -n https://api.heroku.com/
expect -d -c " spawn heroku.bat pgbackups:capture --expire --app gw-inspector expect {
"Email:" { send -- "myEmailHere\r"; exp_continue}
"Password (typing will be hidden):" { send -- "myPWhere\r" }
timeout { puts "timed out during login"; exit 1 } } " sleep 2 echo "first"
这应该工作但尽管变量的回显失败,给我提供了一个线索,说明该变量没有被调用,但我正在测试直接对变量进行硬编码以将其作为变量消除。但正如你可以通过我的输出所看到的那样,不仅回声没有产生任何效果,也没有任何线索表明任何诊断正在通过,这让我怀疑脚本是否被称为从期望运行,以及产生的结果命令。重申一下,heroku.bat命令在预期关闭之外工作,但结果在上面。直接在上面的命令的结果是:
/usr/bin/bash
{
"links":[
{
"rel":"schema",
"href":"https://api.heroku.com/schema"
}
]
}
我做错了什么,会告诉我诊断说明?
'HEROKU_LOGIN'和'HEROKU_PW'是否是'.bashrc'文件中声明的环境变量? – Dinesh 2014-10-10 08:38:34