为什么lftp将URL的一部分解释为新命令?

时间:2011-07-30 17:44:23

标签: bash lftp

为什么我会收到这些错误?

Unknown command pass=user.
Unknown command key=site-key.

可能是因为我正在使用 lftp 或者是什么?

这是我的bash脚本:

#!/bin/sh

##########################################################################
#
# Send queued CiviMail and process back channel for CiviCRM v2.2+
# Make this executable and invoke from cron every (say) 15 minutes
# Not yet tested: no lock on this if previous cron hadn't finished
# but civimail.cronjob.php and CiviMailProcessor.php are multi-entrant
#
##########################################################################
#
# Per-host configuration
#

drupalAuthUser='user'
drupalAuthPass='password'
civicrmSiteKey='site-key'

imapHost='civicrm.example.org'
imapUser='civicrm@example.org'
#imapPass='password'
#
# Prepare URL
#
crmbinurl="http://$imapHost/sites/all/modules/civicrm/bin"
crmauthn="?name=$drupalAuthUser&pass=$drupalAuthPass&key=$civicrmSiteKey"
#
echo "Run Drupal cron then check for and send queued CiviMail"
### Heading ##
civimail="${crmbinurl}/civimail.cronjob.php${crmauthn}"
echo $civ
## Heading ##imail
lftp -c "get $civimail > /dev/null"
#
# Wait 10 seconds
#
sleep 2
#
# echo "Process CiviMail backchannel"
#
backchan="${crmbinurl}/CiviMailProcessor.php${crmauthn}"
echo $backchan
## Heading ##
lftp -c "get $backchan > /dev/null"

运行./civicrmcron.sh会显示此输出:

Run Drupal cron then check for and send queued CiviMail
http://civicrm.example.org/sites/all/modules/civicrm/bin/civimail.cronjob.php?name=user&pass=password&key=site-key
Unknown command `pass=user'.
Unknown command `key=site-key'.
[22328] Moving to background to complete transfers...
http://civicrm.example.org/sites/all/modules/civicrm/bin/civimail.cronjob.php?name=user&pass=password&key=site-key
Unknown command `pass=user'.
Unknown command `key=site-key'.
[22332] Moving to background to complete transfers...

2 个答案:

答案 0 :(得分:1)

这是因为您的网址中的&符号为$ crmauthn。如果你使用单引号它应该工作:

crmauthn='?name='${drupalAuthUser}'&pass='${drupalAuthPass}'&key='${civicrmSiteKey}

或:

crmauth="'?name='${drupalAuthUser}'&pass='${drupalAuthPass}'&key='${civicrmSiteKey}"

答案 1 :(得分:0)

使用链接代替 lftp

#!/bin/bash

drupalAuthUser="user"
drupalAuthPass="password"
civicrmSiteKey="site-key"

imapHost="civicrm.example.org"
imapUser="civicrm@example.org"
imapPass="password"

crmbinurl="http://${imapHost}/sites/all/modules/civicrm/bin"
crmauthn="?name=${drupalAuthUser}&pass=${drupalAuthPass}&key=${civicrmSiteKey}"

echo "CiviMail CronJob"
civimail="${crmbinurl}/civimail.cronjob.php${crmauthn}"
echo "  * ${civimail}"
links -source ${civimail} > /dev/null

sleep 2

echo "Process CiviMail backchannel"
backchan="${crmbinurl}/CiviMailProcessor.php${crmauthn}"
echo "  * ${backchan}"
links -source $backchan > /dev/null