初心者です。crontabがどうしても機能しなくて困っています。
一時的にUbuntu 16.04 LTSを使っていますが、普段はWindowsを使っていますので、いろいろネットで調べましたが、解決できなくてお手上げ状態です。
一応自分でやったことを書きます。なんとなくですが、何か根本的なことであったり、非常に初歩的なケアレスミスをしている気がします。
よろしくお願いします。
・crontab -eからnanoというエディターみたいなソフトを使って、「* * * * * touch /test /result.txt 2>&1」というコマンドを設定しています。このコマンドはcronが動くかどうか試すために設定しているだけで、実際cronを使ってやりたいことは別のことです。touch他のコマンドもいくつか試してみましたが、cronは機能しませんでした。そのときは.shというファイルを実行するコマンドだったので、chmodで実行権限を与えましたが、それでも機能しませんでした。
'・touchでtestファイルが作られないだけではなく、result.txtは一切出力されません。
・GUIのシステムモニターを起動しても、「crond」「cron」という文字列を含むプロセスはありません。
・「crontab -l」と打つと、このような途中から切れた文字列が出てきます。
~$ /result.txt 2>&1bin:/bin:/usr/sbin:/usr/binn(8)
・「crontab -e」と打つと、「/tmp/crontab.x0x0x0/crontab」というファイルを編集しているようです。(xは英字で0は数字です。)
・「crontab -e」と打つと、中身はこのようになっています。コメントアウト以外の部分を自分で設定しました。最初の4行はあってもなくてもcrontabは機能しません。
'# Edit this file to introduce tasks to be run by cron.
'#
'# Each task to run has to be defined through a single line
'# indicating with different fields when the task will be run
'# and what command to run for the task
'#
'# To define the time you can provide concrete values for
'# minute (m), hour (h), day of month (dom), month (mon),
'# and day of week (dow) or use '*' in these fields (for 'any').'#
'# Notice that tasks will be started based on the cron's system
'# 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
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
HOME=/
-
-
-
-
- touch /test /result.txt 2>&1
-
-
-
'・sudo service cron statusとターミナルに打つと、このような文字列が出てきます。(これはネットに公開するのはまずいでしょうか?)
● cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since 土 2017-01-28 16:44:43 JST; 23h ago
Docs: man:cron(8)
Main PID: 650 (cron)
Tasks: 1 (limit: 512)
CGroup: /system.slice/cron.service
└─650 /usr/sbin/cron -f
1月 29 12:17:01 username CRON[12786]: pam_unix(cron:session): session opened for user root by (uid=0)
1月 29 12:17:01 username CRON[12787]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
1月 29 13:17:01 username CRON[14515]: pam_unix(cron:session): session opened for user root by (uid=0)
1月 29 13:17:01 username CRON[14516]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
1月 29 13:17:01 username CRON[14515]: pam_unix(cron:session): session closed for user root
1月 29 14:17:01 username CRON[15658]: pam_unix(cron:session): session opened for user root by (uid=0)
1月 29 14:17:01 username CRON[15659]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
1月 29 14:17:01 username CRON[15658]: pam_unix(cron:session): session closed for user root
1月 29 15:17:01 username CRON[17319]: pam_unix(cron:session): session opened for user root by (uid=0)
'1月 29 15:17:01 username CRON[17320]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/01/29 11:47
2017/01/29 12:38
退会済みユーザー
2017/01/30 10:03
2017/01/30 13:36
退会済みユーザー
2017/01/31 05:56