我的脚本中有一个像这样的命令
MESSAGE=`grep -Po 'MSG.\K[\w\s,.'\'',.:]*' < $FILENAME`
现在运行此命令时,我的输出看起来像这样
Kohl's EDI will be down for scheduled maintenance starting at 12:30 am until
approximately 4:00 am central time on Wednesday June 22nd. Kohl's will not be
able to send or receive EDI or AS2 transmissions during this time. If your
company's AS2 software has an automated process to resend a file after a
failure, Kohl's encourages your company to enable the resend process. This is
also a reminder for AS2 trading partners that Kohl's AS2 certificate will be
changing at 11:00 am central time on Tuesday June 21st.
现在在完成整个操作之后,我会将命令的结果传递给将要使用的变量,以便我可以将结果存储到mysql数据库
问题是我该怎么做?
答案 0 :(得分:0)
确保你从服务器连接到mysql然后你可以在插入语句中传递MEASSGE变量\"$MESSAGE\"
- \
是因为用双引号包装消息以获得有效的插入语句。
测试:我没有足够大的列来存储整个邮件,所以我将它修剪得很少以适应列:
> MESSAGE="Kohl's EDI will be down for scheduled maintenance starting at 12:30 am until
approximately 4:00 am central time on Wednesday June 22nd. Kohl's will not be
able to send or receive EDI or AS2 transmissions during this time. If your
company's AS2 software has an automated process to resend a file after a
"
> sql "insert into at_test_run (run_id,run_error) values ('10000111',\"$MESSAGE\");"
> sql "select run_id,run_error from at_test_run where run_id='10000111'"
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| run_id | run_error |
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 10000111 | Kohl's EDI will be down for scheduled maintenance starting at 12:30 am until
approximately 4:00 am central time on Wednesday June 22nd. Kohl's will not be
able to send or receive EDI or AS2 transmissions during this time. If your
company's AS2 software has an automated process to resend a file after a
|
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+