shell脚本请教
[*]#!/bin/bash[*]PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin;
[*]rm -rf /root/testfile/*.*
[*]cd /root/testfile/
[*]date >> /root/test.txt
[*]/usr/bin/lftp -u root,password sftp://123.123.123.123 -e "pget -n 30 /root/ubuntu-16.04-server-amd64.template;exit" >> /root/test.txt复制代码
上面代码保存成/root/test.sh
直接执行能够在test.txt写入:
2016年 05月 17日 星期二 15:50:55 CST
113242320 bytes transferred in 22 seconds (5.02M/s)
但是用crontab执行的话
*/5 * * * * sh /root/test.sh > /dev/null 2>&1
test.txt里只有“2016年 05月 17日 星期二 15:50:55 CST”,没有“113242320 bytes transferred in 22 seconds (5.02M/s)”。
看路由器流量图是有流量的 #将.sh文件设为可执行(777)
chmod +x test.sh
优秀的苦瓜 发表于 2016-5-17 16:48
> /dev/null 2>&1
这个意思
去掉一样不行。感觉是lftp问题。
hitsword 发表于 2016-5-17 16:56
去掉一样不行。感觉是lftp问题。
你用root权限执行的吗? /usr/bin/lftp -u root,password sftp://123.123.123.123 -e "pget -n 30 /root/ubuntu-16.04-server-amd64.template;exit" >> /dev/null 2>&1
quyiqu 发表于 2016-5-17 16:31
#将.sh文件设为可执行(777)
chmod +x test.sh
已经是777.脚本内容是执行了的。
walkman660 发表于 2016-5-17 16:59
/usr/bin/lftp -u root,password sftp://123.123.123.123 -e "pget -n 30 /root/ubuntu-16.04-server-amd64 ...
我是要每次执行都记录。 去掉脚本里面重定向到test.txt,在cron里面重定向[*]*/5 * * * * /root/test.sh &> /root/test.txt复制代码
leoynx 发表于 2016-5-17 17:23
去掉脚本里面重定向到test.txt,在cron里面重定向
还是不行。把pget的路径写全试下吧
cgs3238 发表于 2016-5-17 22:11
把pget的路径写全试下吧
pget不是程序。已经是完整路径。pget是lftp里面的一个参数
页:
[1]
2