Results 1 to 7 of 7

Thread: Issue with script running from 'cron'

  1. #1
    Join Date
    Feb 2011
    Beans
    48

    Issue with script running from 'cron'

    Hi,

    I'm having a weird issue.

    I have a script that runs perfectly when the system boots up and when I run it manually, but fails when it's started by 'cron'.

    This is the script (the real script is actually much bigger, but this are the things I'm having problems with):

    Code:
    #!/bin/bash
    
    MOUNT_DIR="/home/user/Dropbox/crypt"
    VAULT_FILE="/home/user/Dropbox/truecrypt-file"
    KEY_FILE="/home/user/Escritorio/truecrypt-keyfile"
    
    truecrypt -d "${VAULT_FILE}"
    zenity --warning --text="Volume un-mounted.\n Starting Dropbox.";
    
    # Piece of code where Dropbox is executed and after is finished, stopped. This works fine.
    
    truecrypt --keyfiles="$KEY_FILE" "${VAULT_FILE}" "${MOUNT_DIR}"
    Now, neither the 'zenity' nor the 'truecrypt' command will work when the script is launched from 'cron'. I know 'cron' is launching the script correctly because I have a log output (not shown in this excerpt of the script) that records whenever the script is started.

    This is the 'cron' command I use by the way:

    Code:
    0 */10 * * * /home/gabriel/check-dropbox.sh
    I use this because I see no reason why Dropbox should run more than twice a day (once when the system starts, and once more 10 hours later)

    Any ideas?

    Regards,
    Gabriel

  2. #2
    Join Date
    May 2010
    Location
    Tewkesbury uk
    Beans
    7,916
    Distro
    Ubuntu Development Release

    Re: Issue with script running from 'cron'

    Hi

    Cron does not have your environmental settings. Try using the full path to truecrypt and zenity.

    Kind regards
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

  3. #3
    Join Date
    Feb 2011
    Location
    Maryland
    Beans
    2,251

    Re: Issue with script running from 'cron'

    edit using
    Code:
    sudo crontab -e

  4. #4
    Join Date
    Jul 2009
    Location
    London
    Beans
    1,480
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Issue with script running from 'cron'

    Hi, cron is not running in a graphical session as you are, so zenity has no way of knowing what X display you want your warning notifications displayed on.

    add the line:
    Code:
    export DISPLAY=:0.0
    to your script before the call to zenity.

  5. #5
    Join Date
    Feb 2011
    Beans
    48

    Re: Issue with script running from 'cron'

    Hi,

    thanks for the replies.

    @collisionystm: editing crontab with sudo didn't help

    @ matt_symes: writing the full path to 'truecrypt' made it work

    @DaithiF: added that line and 'zenity' in now capable of displaying windows

    Thanks to all!

    One more question if it's not too much trouble

    I'm trying to make the script realize if a file within a given folder is opened (this is so 'Dropbox' won't sync un-encrypted files inside the un-encrypted folder)

    I've tried both this codes:

    Code:
    for f in /path/to/folder/*
    do
        lsof "$f" | grep -q COMMAND &>/dev/null
        if [ $? -eq 0 ]
        then
            echo "Warning: Open file $f"
        fi
    done
    and

    Code:
    if mount | grep "${MOUNT_DIR}" >/dev/null; then
         dir="/path/to/folder/"
         lsof +D $dir | grep -q COMMAND &>/dev/null
         if [ $? -eq 0 ]
         then
           export DISPLAY=:0.0
           zenity --warning --text="Warning: Open files found in $dir \n Please close ALL open files BEFORE moving on.";
         fi
    fi
    The first method can identify single files, the second only tells you that there's some file is opened in that dir.

    The problem with both this methods is that they both fail to see files opened with 'gedit', basically any image file or *zip files (opened with 'Ark'); this are all I've tried. They do warn me about opened *.mp3's or *.doc files.

    'TrueCrypt' has an internal option to detect opened files, but that won't halt the script. I want to check for ANY opened file, display a warning through 'zenity' if one is found, and then give the user the option to exit the script by clicking one of 'zenity's' buttons (either 'Ok' or 'Cancel'; I think they are both displayed with 'zenity --info')

    Can this be done?

    Thanks!

  6. #6
    Join Date
    Feb 2011
    Beans
    48

    Re: Issue with script running from 'cron'

    Well I guess I'll just open another post with the questions about 'lsof'

    To close this one, I'll add that I got it working adding 'export DISPLAY=:0.0' before the 'truecrypt' call. It looks lie this:

    Code:
    export DISPLAY=:0.0
    /usr/bin/truecrypt -d "${VAULT_FILE}"  "${MOUNT_DIR}"
    Truecrypt could work with less parameters (perhaps just 'truecrypt -d'), I didn't try
    Last edited by Gaba_p; April 28th, 2011 at 04:32 PM. Reason: correction

  7. #7
    Join Date
    May 2008
    Beans
    3

    Lightbulb Re: Issue with script running from 'cron'

    I know this is a old thread.. but I just wanted to add that it should also work if you add the -t switch to Truecrypt like this:

    Code:
    /usr/bin/truecrypt -t -d "${VAULT_FILE}"  "${MOUNT_DIR}"
    See the Truecrypt --help reference for more information:

    -t, --text
    Use text user interface. Graphical user interface is used by default if available. This option must be specified as the first argument.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •