为什么我在 gnome-schedule 下的 shell 脚本中没有得到 zenity 的输出

为什么我在 gnome-schedule 下的 shell 脚本中没有得到 zenity 的输出

我正在使用 Fedora Linux 12,并打算尽快更新到最新版本。为了为此做好准备,我在外部驱动器上进行了完整备份。我想使用 rsync 使此备份保持最新,系统描述如下:http://webgnuru.com/linux/rsync_incremental.php

为了安排备份,我想使用 gnome-schedule,并使用 zenity 将令人放心的消息输出到我的计算机屏幕上。

在我投入所有宝贵的精力之前,我正在小规模地测试它,这里是我的 shell 脚本的列表。更新工作完美,所以我的问题是:为什么我最后没有从 zenity 命令中得到任何输出?

#!/bin/bash
# Adapted from: http://webgnuru.com/linux/rsync_incremental.php
#  Website Backup Script
#======================================================================
# Define Variables
# Todays date in ISO-8601 format e.g. 2013-10-19:
DAY0=`date -I` 
# Yesterdays date in ISO-8601 format:
DAY1=`date -I -d "1 day ago"`
# The source directory:
SRC="/home/Harry/testrsync/bravo/"
# The target directory:
TRG="/home/Harry/testrsync/backups/$DAY0" 
# The link destination directory:
LNK="/home/Harry/testrsync/backups/$DAY1"
#The rsync options:
OPT="-avh --delete --link-dest=$LNK"
#======================================================================
#Execute the backup
rsync $OPT $SRC $TRG
#Delete old backups cyclically
# for my tests I am going to use a three day cycle
DAY4=`date -I -d "4 days ago"`
#Delete the backup from 4 days ago, if it exists
if [ -d /home/Harry/testrsync/backups/$DAY4 ]
then
rm -r /home/Harry/testrsync/backups/$DAY4
fi
zenity --info --text='Backup complete' --title="Backup Test"

答案1

经过两天与晦涩的语法和晦涩的参考资料的斗争后,我找到了答案。

在 Gnome Schedule 的帮助文档中写道:

9.2. Setting DISPLAY variable for tasks that will launch once

When you are creating or modifying a task, you can define the DISPLAY 
variable in the script text box. Make the definition at the beginning of the
script.

9.3. Setting DISPLAY variable for tasks that will launch recurrently

Gnome Schedule does not support yet setting environment variables for
recurrent tasks, but it will do soon. In the meantime, you can manually create
a script that first defines DISPLAY variable and then calls the graphical
application. Finally, you can create a recurrent task to launch the script.

fred.sh因此,我创建了包含以下内容的脚本文件:

#!/bin/sh
DISPLAY=:0.0
#home/Harry/testrsync/trial_bak.sh
testrsync/trial_bak.sh

并将脚本fred.sh用作计划任务。我在问题中命名了测试任务脚本trial_bak.sh。请注意,调用的脚本fred.sh必须通过主目录引用,即作为最后一行而不是上面注释掉的行。现在它可以工作了,我弹出了所需的信息窗口。

请注意,这意味着 Gnome Schedule 配置中的“运行一次”预览可能会起作用,就像它对我来说令人困惑的那样(我认为它可能会使用at而不是cron),但需要将其作为循环任务进行测试才能确定。

起初我添加DISPLAY=:0.0到问题中脚本的最后一行,但后来发现这是没有必要的

我曾经xdpyinfo | less检查需要使用什么DIPSPLAY=...less因为大量的信息被大量生产出来。

最后,我描述了我的发现,但并不声称它是确定的或完整的,甚至是完全正确的。我对任何人都可以添加的任何相关额外信息感兴趣,

相关内容