AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1481989
Accepted
TVG
TVG
Asked: 2023-08-11 20:55:10 +0800 CST2023-08-11 20:55:10 +0800 CST 2023-08-11 20:55:10 +0800 CST

crontab 不工作

  • 772

以下是我的 crontab 的内容:

toto@toto-pc:~$ crontab -l
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command

21 15 * * * DISPLAY=:0 /usr/bin/freefilesync /home/toto/Backup_launch/Backup_on_My_Passport.ffs_batch >/home/toto/crontab_log 2>&1
*/10 * * * * /home/toto/Backup_launch/Backup_on_OneDrive.sh

toto@toto-pc:~$

然后,我预计FreeFileSync 每天 15:21 执行Backup_on_My_Passport.ffs_batch批处理作业,并且脚本Backup_on_OneDrive.sh每 10 分钟执行一次。

Backup_on_OneDrive.sh每 10 分钟正确执行一次,但 crontab 永远不会启动Backup_on_My_Passport.ffs_batch。

以下是crontab_log文件的内容:

Authorization required, but no authorization protocol specified

15:21:01: Error: Unable to initialize GTK+, is DISPLAY set properly?

我认为 DISPLAY 的值是正确的:

toto@toto-pc:~$ echo $DISPLAY
:0
toto@toto-pc:~$
bash
  • 2 2 个回答
  • 59 Views

2 个回答

  • Voted
  1. Best Answer
    TVG
    2023-08-11T22:14:56+08:002023-08-11T22:14:56+08:00

    看来是韦兰的问题。然后,在 /etc/gdm3/custom.conf 中,我取消注释了#WaylandEnable=false强制登录屏幕使用 Xorg 的行。

    然后我不得不改变DISPLAY=:0,DISPLAY=:1因为echo $DISPLAY返回1。

    现在它正在按预期工作。

    • 3
  2. waltinator
    2023-08-11T23:19:46+08:002023-08-11T23:19:46+08:00

    由于cron将条目的命令行部分传递crontab到/bin/sh(可能是到 的链接/bin/dash),这是一个更简单的 shell,因此应该1) 将命令包装在#!/bin/bash脚本中;2) 从您的crontab. 这将使调试、操作、日志记录等变得更加容易,并且您永远不必担心不支持的bash功能。sh

    您也可能会从我的回答中受益(https://unix.stackexchange.com/questions/673908/why-crontab-doesnt-execute-a-scheduled-bash-script/673918#673918)。

    • -1

相关问题

  • 同时复制到两个位置

  • 如何在 shell 脚本中创建选择菜单?

  • 从 bash 迁移到 zsh [关闭]

  • bashrc 还是 bash_profile?

  • 备份 bash 脚本未压缩其 tarball

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve