代码之家  ›  专栏  ›  技术社区  ›  Dolphin

如何在macosx下cron任务中使用gitlab authorthize缓存

  •  0
  • Dolphin  · 技术社区  · 5 年前

    我正在使用cron任务每分钟更新一次代码:

     */1 * * * * /Users/dolphin/Library/"Mobile Documents"/com~apple~CloudDocs/Document/source/dolphin/dolphin-scripts/bash/cron/auto-check-code.sh >> /Users/dolphin/shell.log
    

    From dolphin@dolphins-MacBook-Pro.local  Wed Dec 25 11:30:00 2019
    Return-Path: <dolphin@dolphins-MacBook-Pro.local>
    X-Original-To: dolphin
    Delivered-To: dolphin@dolphins-MacBook-Pro.local
    Received: by dolphins-MacBook-Pro.local (Postfix, from userid 501)
        id 9E2641279C5F; Wed, 25 Dec 2019 11:30:00 +0800 (CST)
    From: dolphin@dolphins-MacBook-Pro.local (Cron Daemon)
    To: dolphin@dolphins-MacBook-Pro.local
    Subject: Cron <dolphin@dolphins-MacBook-Pro> /Users/dolphin/Library/"Mobile Documents"/com~apple~CloudDocs/Document/source/dolphin/dolphin-scripts/bash/cron/auto-check-code.sh >> /Users/dolphin/shell.log
    X-Cron-Env: <SHELL=/bin/sh>
    X-Cron-Env: <PATH=/usr/bin:/bin>
    X-Cron-Env: <LOGNAME=dolphin>
    X-Cron-Env: <USER=dolphin>
    X-Cron-Env: <HOME=/Users/dolphin>
    Message-Id: <20191225033000.9E2641279C5F@dolphins-MacBook-Pro.local>
    Date: Wed, 25 Dec 2019 11:30:00 +0800 (CST)
    
    + date
    + SOURCE_CODE_BASE_PATH=/Users/dolphin/source/dabai/microservice
    + LOG_PATH=/var/log/shell
    + arr=("soa-misc" "soa-misc-biz" "ws-red-envelope")
    + whoami
    + for index in '"${!arr[@]}"'
    + cd /Users/dolphin/source/dabai/microservice/soa-misc
    + '[' soa-misc == soa-misc1 ']'
    + '[' soa-misc == ws-red-envelope1 ']'
    + git pull origin master
    fatal: could not read Username for 'https://gitlab.208.com': Device not configured
    

    我在候机楼执行成功。这个bash自动检查脚本-代码.sh):

    #!/usr/bin/env bash
    
    # 当使用未初始化的变量时,程序自动退出
    # 也可以使用命令 set -o nounset
    set -u
    
    # 当任何一行命令执行失败时,自动退出脚本
    # 也可以使用命令 set -o errexit
    set -e
    
    # 在执行(execute)脚本之前,打印出执行命令
    set -x
    
    date
    
    SOURCE_CODE_BASE_PATH="/Users/dolphin/source/dabai/microservice"
    LOG_PATH="/var/log/shell"
    
    arr=("soa-misc" "soa-misc-biz" "ws-red-envelope")
    
    whoami
    
    for index in "${!arr[@]}"; do
      cd ${SOURCE_CODE_BASE_PATH}/"${arr[$index]}"
      if [ "${arr[$index]}" == "soa-misc1" ]; then
        git pull
      elif [ "${arr[$index]}" == "ws-red-envelope1" ]; then
        git pull origin master
      else
        git pull origin master
      fi
      echo "update ${arr[$index]}" >>${LOG_PATH}/update-source.log
    done
    
    0 回复  |  直到 5 年前
        1
  •  -1
  •   Dolphin    5 年前

    你可以用这个来解决这个错误。我也面临了一天的问题。

    git remote add origin https://{username}:{password}@github.com/{username}/project.git
    

    SOURCE_CODE_BASE_PATH="/Users/dolphin/source/dabai/microservice"
    LOG_PATH="/var/log/shell"
    
    arr=("soa-misc" "soa-misc-biz")
    
    for index in "${!arr[@]}"; do
      cd ${SOURCE_CODE_BASE_PATH}/"${arr[$index]}"
      if [ "${arr[$index]}" == "soa-misc" ]; then
        git remote set-url origin https://jxq:123@gitlab.208.com/development/soa-misc.git
        git pull
      elif [ "${arr[$index]}" == "soa-misc-biz" ]; then
        git remote set-url origin https://jxq:123@gitlab.208.com/development/soa-misc-biz.git
        git pull origin master
      else
        git pull origin master
      fi
      echo "update ${arr[$index]}" >>${LOG_PATH}/update-source.log
    done