简单的 bash Linux 脚本来运行存储过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20389762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple bash Linux script to run stored procedure
提问by Rio
I need a bash/Linux shell script which will run my stored procedure only on Wednesday.
我需要一个 bash/Linux shell 脚本,它只会在星期三运行我的存储过程。
I am new to Bash shell scripting.
我是 Bash shell 脚本的新手。
Below is what I came up with:
下面是我想出的:
test.sh
测试文件
#!/bin/bash
MYSQL="/usr/bin/mysql --compress -hlocalhost -utest -ptest test";
dayofweek=`date +%a`
#if [ ${dayofweek} ='Wed' ] ; then ${MYSQL} -e "CALL testSummary();"; fi ;
When I run it:
当我运行它时:
sh test.sh, it says:
sh test.sh,它说:
: command not found
: 找不到相关命令
Thank you.
谢谢你。
采纳答案by ray
how about run CALL testSummary()
from mysql prompt?
besides [ ${dayofweek} ='Wed' ]
should be [ ${dayofweek} = 'Wed' ]
, no other issue with your script
CALL testSummary()
从 mysql 提示符运行怎么样?除了[ ${dayofweek} ='Wed' ]
应该是[ ${dayofweek} = 'Wed' ]
,你的脚本没有其他问题
I created a simple testSummary procedure, it only print value of select 1 + 1
, running your script gives me the correct output.
我创建了一个简单的 testSummary 程序,它只打印 的值select 1 + 1
,运行您的脚本会给我正确的输出。
回答by PSkocik
I don't see why you'd be getting the command not found error.
Couldn't the -e "CALL testSummary();"
part be what's giving it?
我不明白为什么您会收到未找到命令的错误。难道这-e "CALL testSummary();"
部分不是给它的吗?
Anyway: You don't need
总之:你不需要
#!/bin/bash
If you're running it with
如果你运行它
$ sh test.sh
Now if you made that script executable with
现在,如果您使该脚本可执行
$ chmod +x test.sh
$ chmod +x 测试.sh
then doing $ ./test.sh
would be tantamount to calling /bin/bash test.sh
.
那么这样做$ ./test.sh
就无异于调用/bin/bash test.sh
.
Make up your mind as to whether you want to use bash or sh. They are different.
决定使用 bash 还是 sh。它们是不同的。
If you want to run something periodically on Linux, you might want to take a look at this: https://help.ubuntu.com/community/CronHowto
如果你想在 Linux 上定期运行一些东西,你可能想看看这个:https: //help.ubuntu.com/community/CronHowto