You are not logged in.

#1 2008-08-14 03:09:12

ou3
Member
Registered: 2008-07-22
Posts: 12

"cannot open display" with cron script

This works fine from the CLI, but when it runs with the cron daemon, the log file shows "xfburn: cannot open display."  How do I go about fixing this?

#!/usr/bin/perl -w

`xfburn --version > /home/tim/scripts/blah.log`;

"Luck is the residue of design." — Branch Rickey

Offline

#2 2008-08-14 03:55:29

zyghom
Member
From: Poland/currently Africa
Registered: 2006-05-11
Posts: 432
Website

Re: "cannot open display" with cron script

one thing is DISPLAY:  DISPLAY=:0.0
second is user:

function xue() {  XUSER=` who | awk '$2 == ":0" { print $1 }'`
if [ -n "${XUSER}" ]; then  su - ${XUSER} -c "DISPLAY=:0.0 $1"  fi }

try this

Last edited by zyghom (2008-08-14 03:57:25)


Zygfryd Homonto

Offline

#3 2008-08-14 07:55:47

ou3
Member
Registered: 2008-07-22
Posts: 12

Re: "cannot open display" with cron script

Hmm I'm not really sure what to do with that.  I'll post the whole thing.  This is my first time writing in perl, so I'm sure it's really inefficient and ugly.

It's supposed to grab 'svn info' from all my svn packages in /var/local/abs, find my currently installed versions of the svns, and write the results to ~/scripts/svn-updates/outdated.log file.

It works correctly when I run it from the command line, but when I put it in cron.daily, "@svninfo = `$pkgname --version --display=:0.0`;" doesn't work.

#!/usr/bin/perl -w
use strict;

our (@svns, %local_revs, %latest_revs);
our $svn_dir = "/var/abs/local";
our $outdated_log = "/home/tim/scripts/svn-updates/outdated.log";

# Get list of local svn packages
sub get_svns {
    my ($name, @svns_results);

    opendir(DIR, $svn_dir) or die "Error opening $svn_dir: $!";
    foreach $name (readdir(DIR)) {
        if($name =~ /(.*)-svn$/) {
            push(@svns_results,$1);
        }
    }
    closedir(DIR);

    return @svns_results;
}

# Get latest svn revisions
sub get_latest_revs {
    my ($pkgname, $svntrunk, $i, @svninfo, %latest_revs_results);

    foreach $pkgname (@_) {
        # Find trunk path in PKGBUILD
        open(INFILE, "$svn_dir/$pkgname-svn/PKGBUILD");        
        while(<INFILE>) {
            if(/^_svntrunk="(.*)"/) {
                $svntrunk = $1;
            }
        }
        close(INFILE);

        # Grab svn info on current package
        @svninfo = `svn info $svntrunk`;

        # Add latest revision to hash table
        foreach $i (@svninfo) {
            if($i =~ /^Revision: (\w*)/) {
                $latest_revs_results{$pkgname} = $1;
            }
        }
    }

    return %latest_revs_results;
}

# Get local svn revisions
sub get_local_revs {
    my ($pkgname, $j, @svninfo, %local_revs_results);

    foreach $pkgname (@_) {
        @svninfo = `$pkgname --version --display=:0.0`;

        # Add local revision to hash table
        foreach $j (@svninfo) {
            if($j =~ /^.*svn-(\w*)/) {
                $local_revs_results{$pkgname} = $1;
            }
        }
    }

    return %local_revs_results;
}

# Write outdated packages to $outdated_log
sub write_outdated {
    my $pkg;

    `echo > $outdated_log`;

    foreach $pkg (@_) {
        unless($local_revs{$pkg}==$latest_revs{$pkg}) {
            `echo "$pkg $local_revs{$pkg} ($latest_revs{$pkg})" >> $outdated_log`;
        }
    }
}

# Main
@svns = &get_svns;
%latest_revs = &get_latest_revs(@svns);
%local_revs = &get_local_revs(@svns);
&write_outdated(@svns);

"Luck is the residue of design." — Branch Rickey

Offline

#4 2008-08-19 00:40:35

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: "cannot open display" with cron script

The message you are getting is saying that your program cannot be run because your display variable is not set. Cron does not keep that variable. In order to make the program run you must set that variable manually with

export DISPLAY=":0.0"

. Then you can issue the command to run your program. What zyghom was saying about the user is that you must run that program as the owner of the X display otherwise the command 'xhost +' will have to be run to allow all users to run the display.

Offline

Board footer

Powered by FluxBB