Page 15 of 20 FirstFirst ... 51314151617 ... LastLast
Results 141 to 150 of 191

Thread: How-to for crontab

  1. #141
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: How-to for crontab

    Perhaps try this:
    Edit your crontab to include
    Code:
    DISPLAY=:0
    at the top of the file.

    This may or may not work, but if it does, here is the explanation:
    cron runs commands in a stripped-down environment that doesn't include DISPLAY. Programs with GUIs often read DISPLAY to determine where to place its graphics.

  2. #142
    Join Date
    May 2009
    Location
    Redmond, WA
    Beans
    9
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How-to for crontab

    I must be doing something wrong. I've written a script to back up my system:


    #!/bin/bash

    tar cvpzf /var/lib/mythtv/videos/Backup/mythdown_backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/var/lib/mythtv/videos --exclude=/var/lib/mythtv/recordings /


    And placed the script named backup in the /sbin directory. When I type (from the /sbin directory):

    sudo backup

    everything works great.

    I've tried editing the crontab by typing:

    sudo crontab -e

    and then adding my script (30 19 * * * /sbin/backup).

    The problem is the script will run, but will only backup a small portion of my system.

    What am I doing wrong? Why does the script work from the command line, but not from cron?

    Any help will be greatly appreciated.

  3. #143
    Join Date
    Sep 2007
    Location
    Pteleos Greece
    Beans
    408
    Distro
    Ubuntu Development Release

    Re: How-to for crontab

    Quote Originally Posted by jaketrunk View Post
    I must be doing something wrong. I've written a script to back up my system:


    #!/bin/bash

    tar cvpzf /var/lib/mythtv/videos/Backup/mythdown_backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/var/lib/mythtv/videos --exclude=/var/lib/mythtv/recordings /


    And placed the script named backup in the /sbin directory. When I type (from the /sbin directory):

    sudo backup

    everything works great.

    I've tried editing the crontab by typing:

    sudo crontab -e

    and then adding my script (30 19 * * * /sbin/backup).

    The problem is the script will run, but will only backup a small portion of my system.

    What am I doing wrong? Why does the script work from the command line, but not from cron?

    Any help will be greatly appreciated.
    try using #!/bin/sh
    "Computers are like air conditioners, when you open WINDOW$ they stop working."
    Όσο ζώ μαθαίνω ...
    If Microsoft ever does applications for Linux it means I've won.
    Linus Torvalds

  4. #144
    Join Date
    May 2009
    Location
    Redmond, WA
    Beans
    9
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How-to for crontab

    please see below
    Last edited by jaketrunk; June 10th, 2009 at 05:15 PM. Reason: forgot quote

  5. #145
    Join Date
    May 2009
    Location
    Redmond, WA
    Beans
    9
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How-to for crontab

    Quote Originally Posted by Gourgi View Post
    try using #!/bin/sh
    I made the changes, but still the same result. When run from the command line with sudo the script produces a full backup (~800 megs). When run from crontab, the file is only about 11 megs. Is there a way I can see what is causing the backup to end prematurely?

  6. #146
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: How-to for crontab

    Perhaps try changing
    Code:
    30 19 * * * /sbin/backup
    to
    Code:
    * * * * * /sbin/backup 1>/tmp/backup.out 2>&1
    Then wait a minute (for the cronjob to run) and then look in /tmp/backup.out.
    It should contain all the output from stdout and stderr.
    Look for any errors. That may give us a clue.

    I think I recall one thread where the mere fact that stdout and stderr was directed somewhere was enough to make the cronjob succeed (whereas before it kept bailing out early). I haven't been able to reproduce this problem on my machine, but maybe you will find this true for you too.

  7. #147
    Join Date
    May 2009
    Location
    Redmond, WA
    Beans
    9
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Talking Re: How-to for crontab

    Quote Originally Posted by unutbu View Post
    Perhaps try changing
    Code:
    30 19 * * * /sbin/backup
    to
    Code:
    * * * * * /sbin/backup 1>/tmp/backup.out 2>&1
    Then wait a minute (for the cronjob to run) and then look in /tmp/backup.out.
    It should contain all the output from stdout and stderr.
    Look for any errors. That may give us a clue.

    I think I recall one thread where the mere fact that stdout and stderr was directed somewhere was enough to make the cronjob succeed (whereas before it kept bailing out early). I haven't been able to reproduce this problem on my machine, but maybe you will find this true for you too.
    That did it! The script ran perfectly. Thank you so much for your help! Can you tell me in noob terms what "1>/tmp/backup.out 2>&1" does?

    Thanks again!!

  8. #148
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: How-to for crontab

    Wonderful. I'm glad it worked for you jaketrunk.

    Usually when you run a program from the terminal, the program has a notion of "stdout" and "stderr". When a program prints something to stdout, you see it on the screen.
    stderr is similar to stdout except it is used for the program's error messages. Usually it is also printed in the terminal's window. Both stdout and stderr can be redirected to a single file, or to different files, or to /dev/null (a special file, where everthing sent there gets ignored.)

    In contrast to programs run in the terminal, when you run cronjobs, stdout and stderr are not directed anywhere by default. (If you set up a mail transfer agent, however, you can get each cronjob's stdout and stderr to be sent to your mailbox...)

    "1>/tmp/backup.out" tells /sbin/backup to send stdout to /tmp/backup.out.
    "2>&1" tells /sbin/backup to send stderr to wherever stdout is pointed to.

    The numbers 1 and 2 are file descriptors. By convention, file descriptor 1 is stdout, and file descriptor 2 is stderr.
    Last edited by unutbu; June 11th, 2009 at 12:13 PM.

  9. #149
    Join Date
    May 2009
    Location
    Redmond, WA
    Beans
    9
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How-to for crontab

    Unutbu, that makes sense. Thank you for the valuable info. I will keep in mind as a work on additional scripts.

  10. #150
    Join Date
    Jun 2009
    Beans
    7

    Re: How-to for crontab

    hello guys im having problem with my crontab, im still a newbie in this, i tried created a crontab that will make my com restart (just to learn how to use it,lol) and this is the line i wrote:

    00 12 * * * /sbin/shutdown -r

    however,it does not seem to work, i create this crontab in root account so i dont think it has got to do with privilege problem, someone please help me on this

Page 15 of 20 FirstFirst ... 51314151617 ... LastLast

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
  •