使用Ansible在远程服务器上运行cronjob时执行远程脚本时出现问题

时间:2019-05-13 13:42:17

标签: ubuntu cron ansible

我正在root用户下设置cronjob来通过Ansible备份我的Jenkins服务器。 cronjob有望每周运行从我的本地文件夹复制的shell脚本。

下面的代码是我产生的

- name: copy backup scripts to the server
  copy:
    src: ./../../scripts/swift-backup.sh
    dest: /scripts/swift-backup.sh
    owner: root
    group: root
    mode: 777

- name: check if file exists
  file:
    path: /scripts/swift-backup.sh
    state: file

- name: Automatic backup the VM
  cron: 
    name: "Automatic backup to swift with rclone"
    minute: "0"
    hour: "0"
    weekday: "0"
    job: "sh /scripts/swift-backup.sh"

check if file exists成功找到了文件。我什至在服务器上手动找到了脚本。但是,这是我从cron作业中获得的日志:

sh: 0: Can't open scripts/swift-backup.sh

当我执行整个任务时,这是什么问题?这是脚本中的代码:

#!/usr/bin/env bash

. ./../openrc-monsoon3-MLOps
while [ $(rclone lsd monsoon:jenkins_backup_test | wc -l) -ge 3 ] 
do
    # find and remove oldest backup folder
    rclone delete monsoon:jenkins_backup_test/$(rclone lsd monsoon:jenkins_backup_test | head -1 | awk '{print $NF}')
done
# Push file to monsoon
rclone copy backup/ monsoon:jenkins_backup_test -L
rm backup/* -rf

0 个答案:

没有答案