crontab任务无法执行sh脚本
Tofloor
poster avatar
su_bbc
deepin
2015-07-31 08:05
Author
本帖最后由 su_bbc 于 2015-7-31 00:07 编辑

脚本文件·························
脚本文件1··················
#! /bin/sh
while read ip
do
ping -c 2  $ip > /dev/null && echo  $ip >>upip.txt || echo "`date +%F" "%T`" $ip >>downip.txt
done < allip.txt
awk 'NR==FNR{a[$1]=$0;next}NR>FNR{if($1 in a)print a[$1]}' host.txt upip.txt >>1.txt
while read ip
do
./1.exp $ip
done < 1.txt

脚本文件2··············
#! /usr/bin/expect -f
set timeout 5
set ip [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
spawn telnet $ip
expect    "Username:"
send      "$username\r"
expect    "assword:"
send      "$password\r"
expect    "*>"
send      "system\r"
expect    "*]"
#send       "reboot system\r"
#interact
expect eof

crontab任务
*/10 * * * root sh /mnt/resw.sh

cron日志文件
Jul 30 22:48:55 deepin-pc anacron[983]: Anacron 2.3 started on 2015-07-30
Jul 30 22:48:55 deepin-pc cron[931]: (CRON) INFO (pidfile fd = 3)
Jul 30 22:48:56 deepin-pc cron[1045]: (CRON) STARTUP (fork ok)
Jul 30 22:48:56 deepin-pc cron[1045]: Error: bad day-of-week; while reading /etc/crontab
Jul 30 22:48:56 deepin-pc cron[1045]: (*system*) ERROR (Syntax error, this crontab file will be ignored)
Jul 30 22:48:56 deepin-pc anacron[983]: Will run job `cron.daily' in 5 min.
Jul 30 22:48:56 deepin-pc anacron[983]: Jobs will be executed sequentially
Jul 30 22:48:56 deepin-pc cron[1045]: (CRON) INFO (Running @reboot jobs)
Jul 30 22:53:55 deepin-pc anacron[983]: Job `cron.daily' started
Jul 30 22:53:55 deepin-pc anacron[1433]: Updated timestamp for job `cron.daily' to 2015-07-30
Jul 30 22:54:04 deepin-pc anacron[983]: Job `cron.daily' terminated
Jul 30 22:54:04 deepin-pc anacron[983]: Normal exit (1 job run)



大神帮忙解决下················

直接执行脚本可以,任务计划不能执行,报错


Reply Favorite View the author
All Replies
cxbii
deepin
2015-07-31 17:55
#1
对crontab不熟,查下man文档看看能否解决呗
Reply View the author
Feng Yu
deepin
2015-07-31 18:11
#2
Jul 30 22:48:56 deepin-pc cron[1045]: (*system*) ERROR (Syntax error, this crontab file will be ignored)

crontab语法都写错了
Reply View the author
BingoLove
deepin
2015-07-31 18:26
#3
已经提示你语法错误了,你看一下默认的crontab是怎么写的,照葫芦画瓢
  1. ᐅ cat /etc/crontab
  2. # /etc/crontab: system-wide crontab
  3. # Unlike any other crontab you don't have to run the `crontab'
  4. # command to install the new version when you edit this file
  5. # and files in /etc/cron.d. These files also have username fields,
  6. # that none of the other crontabs do.

  7. SHELL=/bin/sh
  8. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

  9. # m h dom mon dow user        command
  10. 17 *        * * *        root    cd / && run-parts --report /etc/cron.hourly
  11. 25 6        * * *        root        test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
  12. 47 6        * * 7        root        test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
  13. 52 6        1 * *        root        test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Copy the Code

Reply View the author
su_bbc
deepin
2015-08-01 07:13
#4
https://bbs.deepin.org/post/31701
已经提示你语法错误了,你看一下默认的crontab是怎么写的,照葫芦画瓢

改了不报错了,但是不能执行脚本
9 23 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /mnt/resw.sh)
日志:
Jul 31 23:09:01 deepin-pc CRON[4394]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /mnt/resw.sh))
脚本执行后会在mnt目录下面生成一个downip.txt文本,但是一直没有生成
Reply View the author
Feng Yu
deepin
2015-08-01 17:20
#5
https://bbs.deepin.org/post/31701
改了不报错了,但是不能执行脚本
9 23 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts -- ...

这个能执行才是怪事
Reply View the author
su_bbc
deepin
2015-08-01 22:47
#6
本帖最后由 su_bbc 于 2015-8-1 15:32 编辑
https://bbs.deepin.org/post/31701
这个能执行才是怪事

怎么才能执行啊,没办法了
46 22 *  *  * cd/mnt && ./resw.sh
日志都提示执行了,但是就没看到结果
Aug  1 23:32:01 localhost CROND[4056]: (root) CMD (cd/mnt && ./resw.sh)
Reply View the author
Feng Yu
deepin
2015-08-02 01:53
#7
https://bbs.deepin.org/post/31701
怎么才能执行啊,没办法了
46 22 *  *  * cd/mnt && ./resw.sh
日志都提示执行了,但是就没看到结果

空格呢?                       。
Reply View the author
BingoLove
deepin
2015-08-02 02:12
#8
本帖最后由 BingoLove 于 2015-8-1 18:14 编辑
https://bbs.deepin.org/post/31701
空格呢?                       。

不是少了个 * 么


楼主似乎是要每10分钟执行一次?
  1. */10 * * * *  root sh /mnt/resw.sh
Copy the Code

才对吧
Reply View the author
Feng Yu
deepin
2015-08-02 05:03
#9
https://bbs.deepin.org/post/31701
不是少了个 * 么

cd /mnt                    .
Reply View the author
su_bbc
deepin
2015-08-02 05:22
#10
https://bbs.deepin.org/post/31701
cd /mnt                    .

已经解决了,谢谢
Reply View the author
su_bbc
deepin
2015-08-02 05:23
#11
https://bbs.deepin.org/post/31701
不是少了个 * 么

我是每天或者每周执行,上面的时间只是测试临时改的时间
Reply View the author