简单的bash Linux脚本来运行存储过程

时间:2013-12-05 01:37:58

标签: linux bash shell unix

我需要一个bash / Linux shell脚本,它只在星期三运行我的存储过程。

我是Bash shell脚本的新手。

以下是我提出的建议:

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 ;

当我运行它时:

sh test.sh,它说:

:找不到命令

谢谢。

2 个答案:

答案 0 :(得分:0)

如何从mysql提示符运行CALL testSummary()? 除了[ ${dayofweek} ='Wed' ]应该是[ ${dayofweek} = 'Wed' ],您的脚本没有其他问题

我创建了一个简单的testSummary过程,它只打印select 1 + 1的值,运行你的脚本会给我正确的输出。

答案 1 :(得分:0)

我不明白为什么你会得到命令not found错误。 -e "CALL testSummary();"部分不能正在给它吗?

反正: 你不需要

#!/bin/bash

如果您使用

运行它
$ sh test.sh

现在,如果您使用

制作该脚本可执行文件

$ chmod + x test.sh

然后执行$ ./test.sh等于调用/bin/bash test.sh

决定是否要使用bash或sh。他们是不同的。

如果您想在Linux上定期运行某些内容,您可能需要查看以下内容:  https://help.ubuntu.com/community/CronHowto