【发布时间】:2017-08-11 13:24:31
【问题描述】:
我有一个名为 test.sh 的 shell 脚本。
#! /bin/bash
mysql -u root -p <<dbEmployee1
use dbEmployee1;
UPDATE EMPLOYEE SET EMPLOYEE_NAME = 'Cyndi' WHERE EMPLOYEE_ID ='1';
SELECT * from EMPLOYEE;
dbEmployee1
mysql -u root -p <<dbBooks
use dbBooks;
SELECT * FROM Author;
dbBooks
在this tutorial 之后,我想做的是让我的脚本每 10 秒运行一次,但结果却低于。
seng@wseng:/$ */10 * * * * /home/seng/Desktop/test.sh
bash: proc/10: Is a directory
我在这里错过了什么或做错了什么?
编辑(执行crontab -e后)
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * cd /home/seng/Desktop/test.sh
【问题讨论】:
-
1) 不能使用cron来按秒进行调度; 2)您没有编辑您的 crontab,只是在命令行上随机放置了一个 cron 表达式
-
@RobbyCornelissen 我应该在哪里添加
crontab?在脚本中? -
在终端中输入“crontab -e”。将出现一个新窗口。并将以下内容添加到您的 crontab 文件中 * * * * * cd /home/seng/Desktop/test.sh # 每分钟执行一次
-
@JohnJoe :按 Esc 并输入 :wq
-
你不能在你的 shell 脚本中使用不带引号的通配符。可能使用
\*或引用此处的文档分隔符。另请参阅stackoverflow.com/questions/4937792/…(关于变量,但同样适用于通配符)。
标签: shell ubuntu cron ubuntu-16.04