找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 102|回复: 16

shell脚本请教

[复制链接]

54

主题

774

回帖

1794

积分

金牌会员

积分
1794
发表于 2016-5-17 16:12:15 | 显示全部楼层 |阅读模式
[ol]
  • #!/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[/ol]复制代码

    上面代码保存成/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)”。

    看路由器流量图是有流量的
  • 回复

    使用道具 举报

    8

    主题

    26

    回帖

    86

    积分

    注册会员

    积分
    86
    发表于 2016-5-17 16:31:40 | 显示全部楼层
    #将.sh文件设为可执行(777)
    chmod +x test.sh
    回复

    使用道具 举报

    54

    主题

    774

    回帖

    1794

    积分

    金牌会员

    积分
    1794
     楼主| 发表于 2016-5-17 16:48:29 | 显示全部楼层

    优秀的苦瓜 发表于 2016-5-17 16:48

    > /dev/null 2>&1

    这个意思

    去掉一样不行。感觉是lftp问题。
    回复

    使用道具 举报

    8

    主题

    26

    回帖

    86

    积分

    注册会员

    积分
    86
    发表于 2016-5-17 16:56:00 | 显示全部楼层

    hitsword 发表于 2016-5-17 16:56

    去掉一样不行。感觉是lftp问题。

    你用root权限执行的吗?
    回复

    使用道具 举报

    79

    主题

    1983

    回帖

    4281

    积分

    论坛元老

    积分
    4281
    发表于 2016-5-17 16:48:00 | 显示全部楼层
    /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
    回复

    使用道具 举报

    54

    主题

    774

    回帖

    1794

    积分

    金牌会员

    积分
    1794
     楼主| 发表于 2016-5-17 16:57:42 | 显示全部楼层

    quyiqu 发表于 2016-5-17 16:31

    #将.sh文件设为可执行(777)
    chmod +x test.sh

    已经是777.脚本内容是执行了的。
    回复

    使用道具 举报

    54

    主题

    774

    回帖

    1794

    积分

    金牌会员

    积分
    1794
     楼主| 发表于 2016-5-17 16:56:00 | 显示全部楼层

    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 ...

    我是要每次执行都记录。
    回复

    使用道具 举报

    73

    主题

    646

    回帖

    1517

    积分

    金牌会员

    积分
    1517
    发表于 2016-5-17 16:59:41 | 显示全部楼层
    去掉脚本里面重定向到test.txt,在cron里面重定向[ol]
  • */5 * * * * /root/test.sh &> /root/test.txt[/ol]复制代码
  • 回复

    使用道具 举报

    0

    主题

    1

    回帖

    4

    积分

    新手上路

    积分
    4
    发表于 2016-5-17 17:14:22 | 显示全部楼层

    leoynx 发表于 2016-5-17 17:23

    去掉脚本里面重定向到test.txt,在cron里面重定向

    还是不行。把pget的路径写全试下吧
    回复

    使用道具 举报

    54

    主题

    774

    回帖

    1794

    积分

    金牌会员

    积分
    1794
     楼主| 发表于 2016-5-17 16:31:00 | 显示全部楼层

    cgs3238 发表于 2016-5-17 22:11

    把pget的路径写全试下吧

    pget不是程序。已经是完整路径。pget是lftp里面的一个参数
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Discuz! X

    GMT+8, 2025-2-3 18:14 , Processed in 0.022032 second(s), 6 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表