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

shell脚本请教

[复制链接]

197

主题

512

回帖

1733

积分

金牌会员

积分
1733
发表于 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")
...........
回复

使用道具 举报

68

主题

890

回帖

2108

积分

金牌会员

积分
2108
 楼主| 发表于 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"`
回复

使用道具 举报

112

主题

4609

回帖

9600

积分

论坛元老

积分
9600
发表于 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分块后 速度快些 不知是否错觉~~
  • 回复

    使用道具 举报

    32

    主题

    665

    回帖

    1496

    积分

    金牌会员

    积分
    1496
    发表于 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
  • 回复

    使用道具 举报

    68

    主题

    890

    回帖

    2108

    积分

    金牌会员

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

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

    看9楼 脚本里

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

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

    使用道具 举报

    36

    主题

    1155

    回帖

    2486

    积分

    金牌会员

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

    使用道具 举报

    17

    主题

    207

    回帖

    475

    积分

    中级会员

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

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

    使用道具 举报

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

    本版积分规则

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

    GMT+8, 2025-7-1 12:14 , Processed in 0.016683 second(s), 3 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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