Cronjob 按计划运行时无法正常工作

Cronjob 按计划运行时无法正常工作

该文件位于/etc/cron.weekly/

#!/bin/sh

# For syncing some files with OneDrive
# Assumes that the sync target is set up as OneDrive:Syncs in rclone

if [ $(id -u) -eq 0 ]; then
    exec sudo -H -u <user> $0 "$@"
fi

notify() {
    #Detect the name of the display in use
    local display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)"

    #Detect the user using such display
    local user=$(who | grep '('$display')' | awk '{print $1}' | head -n 1)

    #Detect the id of the user
    local uid=$(id -u $user)

    sudo -u $user DISPLAY=$display DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus notify-send -a rclone -h string:desktop-entry:alacritty "$@"
}

notify "OneDrive sync" "Sync started..."
flock -n .onedrivesynclock rclone sync -c -L --log-file=logfile --log-level INFO source OneDrive:Syncs
notify "OneDrive sync" "Sync finished!"

显然,logfilesource<user>被替换为正确的值。此脚本在使用时有效,run-parts但当 ir 按计划自动运行时失败。通知有效,但同步无效。我也找不到任何日志。我猜这是某种权限问题,但我不知道如何解决。

相关内容