zoukankan      html  css  js  c++  java
  • node.js 定时执行git pull

    node.js 定时执行git pull
    有时候需要定时执行git pull 的操作
    效果图:

    示例代码:

    let fs = require('fs');
    let child_process = require('child_process');
    let sd = require('silly-datetime');
    
    const argv = process.argv
    
    if (argv.length <= 2) {
        console.log("请指定目标地址!--->例如:node gitpull.js 'D:\xxx\xxxx' ")
        return
    }
    const githref = argv[2]
    
    if (argv.length <= 3) {
      console.log("请指定脚本执行间隔时间!--->例如:60s 则输入:node gitpull.js 'D:\xxx\xxxx'  60")
      return
    }
    const looptime = argv[3]
    
    const timeout = setInterval(() => {
      let time=sd.format(new Date(), 'YYYY-MM-DD HH:mm:ss');
      child_process.exec('git pull', {cwd:githref}, function (error, stdout, stderr) {
        if (error !== null) {
          console.log('exec error: ' + error);
        }else{
          console.log(time+' '+ stdout)
          // console.log(stdout)
        }
    });
    }, looptime * 1000)
    

    运行时候只需要 执行 node 文件名称.js '路径' 时间(时间以s为单位)

  • 相关阅读:
    xt
    UVA 10200 Prime Time (打表)
    CodeForces 540B School Marks
    CodeForces 540C Ice Cave (BFS)
    poj 3250 Bad Hair Day(栈的运用)
    hdu A Magic Lamp
    hdu 4325 Flowers(区间离散化)
    hdu 5500 Reorder the Books
    V2X之标准
    V2X的前生今世
  • 原文地址:https://www.cnblogs.com/justyouadmin/p/11395839.html
Copyright © 2011-2022 走看看