找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
楼主: hitsword

shell脚本请教

[复制链接]

97

主题

320

回帖

969

积分

高级会员

积分
969
发表于 2016-5-17 17:15:25 | 显示全部楼层
xxx=$(/usr/bin/lftp -u root,password sftp://123.123.123.123 -e "pget -n 30 /root/ubuntu-16.04-server-amd64.template;exit")
...........
回复

使用道具 举报

54

主题

774

回帖

1794

积分

金牌会员

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

buzz 发表于 2016-5-23 12:45

xxx=$(/usr/bin/lftp -u root,password sftp://123.123.123.123 -e "pget -n 30 /root/ubuntu-16.04-server ...


试了
xxx=`/usr/bin/lftp -u root,password sftp://123.123.123.123 -e "pget -n 30 /root/ubuntu-16.04-server-amd64.template;exit"`
回复

使用道具 举报

111

主题

4599

回帖

9573

积分

论坛元老

积分
9573
发表于 2016-5-17 17:23:39 | 显示全部楼层
本帖最后由 zyypp 于 2016-5-23 22:45 编辑

这样子呢
[ol]
  • /usr/bin/lftp -c 'get sftp://用户名:密码@IP:端口/root/ubuntu-16.04-server-amd64.template'[/ol]复制代码
    [ol]
  • /usr/bin/lftp -c 'pget -n 30 sftp://用户名:密码@IP:端口/root/ubuntu-16.04-server-amd64.template'
  • [/ol]复制代码

    用time命令看 get 比pget分块后 速度快些 不知是否错觉~~
  • 回复

    使用道具 举报

    30

    主题

    633

    回帖

    1392

    积分

    金牌会员

    积分
    1392
    发表于 2016-5-17 22:06:25 | 显示全部楼层
    看9楼 脚本里
    [ol]
  • 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[/code]
  • 重定向去掉
  • [code]echo date;
  • /usr/bin/lftp -u root,password sftp://123.123.123.123 -e "pget -n 30 /root/ubuntu-16.04-server-amd64.template;exit" [/ol]复制代码
    然后sh 这个脚本看下输出 没问题 最后再重定向到txt
  • 回复

    使用道具 举报

    54

    主题

    774

    回帖

    1794

    积分

    金牌会员

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

    Zeraba 发表于 2016-5-23 21:58

    看9楼 脚本里

    然后sh 这个脚本看下输出 没问题 最后再重定向到txt

    我原来脚本sh都没问题的。只是放到crontab就不行。
    回复

    使用道具 举报

    15

    主题

    496

    回帖

    1051

    积分

    金牌会员

    积分
    1051
    发表于 2016-5-17 17:23:53 | 显示全部楼层
    crontab里面都被你定向到null了,哪来的记录。
    修改成下面
    [ol]
  • */5 * * * * sh /root/test.sh[/ol]复制代码
  • 回复

    使用道具 举报

    15

    主题

    202

    回帖

    457

    积分

    中级会员

    积分
    457
    发表于 2016-5-23 11:05:22 | 显示全部楼层
    cron里这样执行

    */5 * * * * root sh /root/test.sh
    回复

    使用道具 举报

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

    本版积分规则

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

    GMT+8, 2025-2-3 17:52 , Processed in 0.015938 second(s), 4 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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