当我拨打紧急电话时,我正在尝试创建脚本。根据呼叫所在的建筑物,将决定谁会收到电子邮件通知,通知您已发出紧急呼叫。通过一些在线研究,我发现了一个可以发送电子邮件的脚本,但是,一旦我开始添加条件语句,它们似乎就不起作用了。下面是我尝试过的示例,基本上,如果用户扩展名在100和1000之间,则选项1如果大于1000,则选择2。我希望它基于出站CID,但我找不到为此的变量引用。
非常感谢您的协助。
#!/bin/bash
#This script emails the recorded call right after the call is hung up. Below are the variables passed through asterisk
# $1 - year
# $2 - month
# $3 - day
# $4 - Time String
# $5 - Source
# $6 - File
# $7 - Destination
# $dt - Date and Time
dt=$(date '+%m/%d/%Y %r');
echo -e "You have a new call recording to listen to \n\n
The call date and time was $dt \n\n
The call was from $5 \n\n
The call was to $7 \n\n
if ["$5" -gt "100" -a "$5" -lt "1000"]
then
Please see the attached file \n\n" | mail -a /var/spool/asterisk/monitor/$1/$2/$3/$6 -s "New Call Recording" email1@domain.com
elif ["$5" -ge "1000"]
then
Please see the attached file \n\n" | mail -a /var/spool/asterisk/monitor/$1/$2/$3/$6 -s "New Call Recording" email2@domain.com
fi
答案 0 :(得分:1)
这有点混乱。您到处都有一个未终止的字符串,方括号之间的间距不正确,并且您使用数字作为字符串。
由于您使用的是/bin/bash
,因此可以使用Bash条件句。同样,最好使用printf
进行变量插值,而不是将变量嵌入字符串中。尝试这样的事情:
#!/bin/bash
#This script emails the recorded call right after the call is hung up. Below are the variables passed through asterisk
# $1 - year
# $2 - month
# $3 - day
# $4 - Time String
# $5 - Source
# $6 - File
# $7 - Destination
# $dt - Date and Time
dt=$(date '+%m/%d/%Y %r');
printf 'You have a new call recording to listen to \n\n The call date and time was %s \n\n The call was from %s \n\n The call was to %s \n\n' "$dt" "$5" "$7"
if [[ $5 -gt 100 ]] && [[ $5 -lt 1000 ]]; then
printf 'Please see the attached file \n\n' | mail -a "/var/spool/asterisk/monitor/$1/$2/$3/$6" -s "New Call Recording" "email1@domain.com"
elif [[ $5 -ge 1000 ]]; then
printf 'Please see the attached file \n\n' | mail -a "/var/spool/asterisk/monitor/$1/$2/$3/$6" -s "New Call Recording" "email2@domain.com"
fi
如果您是从拨号方案中调用此脚本,为什么不只将CID作为另一个参数呢?
答案 1 :(得分:0)
您可以通过以下方式获取freepbx的出站CID:
/usr/sbin/asterisk -rx 'database show AMPUSER/5555/outboundcid'
5555是CID。
其他选项是在扩展表中的db中查找。