crontab自動執行sql - Linux

Kyle avatar
By Kyle
at 2011-03-11T11:51

Table of Contents

※ 引述《littleheart ( 努力。 )》之銘言:
: 想請問crontab中如何自動執行sql呢?
: 有爬過很多文章, 找到的格式是:
: * * * * * mysql資料夾位置 -u root -pPASSWORD 資料庫名稱 < 須執行之SQL檔位置
: 想請問這個格式是否是正確的呢??
: 因為我試了好幾個方式,都沒有成功自動執行這個SQL
: 已經有在資料庫上執行過SQL, 確定語法是正確的
: 謝謝


請寫出完整指令,剛剛測試一下

vi test.sh

#!/bin/bash
mysql -u root -pxxxxxx -e 'show databases;'

存檔,並且修改 /etc/crontab

*/5 * * * * root /bin/bash /root/test.sh 1>>/root/test.txt

每五分鐘執行一次,重新啟動 crontab

service cron restart


PS: 環境 Ubuntu 10.04

--
PHP MVC CodeIgniter 繁體中文手冊: http://tinyurl.com/mduyv8
PHP MVC CodeIgniter 繁體中文討論區:http://tinyurl.com/yayzoz8
PHP MVC CodeIgniter 中文官方網站: http://tinyurl.com/yatds8n
Appleboy Blog 電腦技術: http://blog.Wu-Boy.com

--
Tags: Linux

All Comments

Puput avatar
By Puput
at 2011-03-12T08:04
可能要使用路徑的絕對路徑

OPEN SUSE 11.4 幾個可能會碰到的 bug

Andrew avatar
By Andrew
at 2011-03-11T03:41
期待了很久 +1 但這次有點小糟糕, 常用的 DSL, smb 在發行版都有問題 1. Bug 678396 - opensuse 11.4: where is linux-atm-lib package? https://bugzilla.novell.com/show_bug.cgi?id=678396 ...

OPEN SUSE 11.4

Poppy avatar
By Poppy
at 2011-03-10T23:33
等了好久的更新 open suse linux 11.4 已經可以下載了,換新版本囉! 下載點如下: http://software.opensuse.org/114/zh_TW - ...

使用Pidgin登入MSN帳號訊息送錯人

Rae avatar
By Rae
at 2011-03-10T23:00
※ [本文轉錄自 MSNmessenger 看板 #1DUEI33_ ] 作者: bangyno (邦吉諾) 看板: MSNmessenger 標題: [問題] 使用Pidgin登入MSN帳號訊息送錯人 時間: Thu Mar 10 22:47:26 2011 以下的1.2.點必填!! -------- ...

Shell Script連db的問題

Hedda avatar
By Hedda
at 2011-03-10T21:15
somevar=`echo and#34;select A from Band#34; | mysql -u $USER -p$PWD -D $DB ` 小弟我在網路google到的寫法差不多都是上面這種寫法 但是有個問題 因為$somevar存的是所有回來的資料,如下 Location Taipei Cit ...

Pidgin 不能傳檔案到msn

Margaret avatar
By Margaret
at 2011-03-10T21:05
之前用Pidgin都沒辦法傳檔案給用msn的朋友 就還要再重開機換win7...= = 昨天我就更新了Pidgin 現在版本是Pidgin 2.7.9 但還是不能傳檔 他會顯示說對方取消了檔案傳輸 但對方明明就沒按取消阿 怎麼辦呢? - ...