Find the answer to your Linux question:
Results 1 to 10 of 10
Hello I'm using CentOS 6 and I trying my first CRON. I've this following file /etc/crontab : Code: SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # For details see man 4 crontabs # ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2011
    Location
    FRANCE !
    Posts
    5

    Question My crontab does not work


    Hello

    I'm using CentOS 6 and I trying my first CRON.

    I've this following file /etc/crontab :
    Code:
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=root
    HOME=/
    # For details see man 4 crontabs
    # Example of job definition:
    # .---------------- minute (0 - 59)
    # |  .------------- hour (0 - 23)
    # |  |  .---------- day of month (1 - 31)
    # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
    # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,$
    # |  |  |  |  |
    # *  *  *  *  *  command to be executed
    37 23 19  8  5 touch cokkkk.txt
    18  *  *  *  * /test/script.sh
    It does not consider my script.sh wich i supposed be executed every hour in the 18th minute... ?

    What is the problem ?

    Thank you !

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,392
    User is missing.
    And may I suggest to write systemwide cronjobs in separate files in /etc/cron.d/<TASK>.cron ?
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Aug 2011
    Location
    FRANCE !
    Posts
    5
    Thanks for your quick reply Irithori !

    Please slowly, I try to understand the first function

    I've add root, so I've change my line for
    Code:
    18  *  *  *  * /test/script.sh root
    and that doesn't change anything !

    Thank you

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,392
    The user is before the command
    Code:
    18  *  *  *  * root /test/script.sh
    About /etc/cron.d vs /etc/crontab:
    Crons are easier to manage, if you separate them by task and write files in /etc/cron.d/
    Because then you can just delete and add files instead of parsing /etc/crontab to find the right lines.
    Also it is easier to define different environments per cronjob.

    So in your case:
    Create a file /etc/cron.d/my_first_cron.cron
    and place your line in there.


    On an additional note:
    There are tasks and cronjobs, that need to be done as root.
    But the goal is to avoid that and use dedicated users for separation and security reasons.
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    Aug 2011
    Location
    FRANCE !
    Posts
    5
    OK that's rulz !

    Just one thing, the upload of the script itself dosent' work in CRON MOD.

    When I execute the script i'ts ok, script.sh is uploaded. But when the CRON execute the script, it cannot upload the script itself. Do I make myself clear?

    Next, I'll try your cron.d.

    Thanks

  6. #6
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    What does the cronlog tell you? It is normally found in:

    /var/log/cron

    You can try redirecting your script output to a log for further trouble-shooting, e.g.:
    Code:
    18  *  *  *  * root /test/script.sh > /tmp/cronjob.log 2>&1
    hth

  7. #7
    Just Joined!
    Join Date
    Aug 2011
    Location
    FRANCE !
    Posts
    5
    In cronjob.log, I have :


    Code:
    Domain=[WIN2003] OS=[Windows Server 2003 R2 3790 Service Pack 2] Server=[Window$
    putting file test.sql as \test.sql (174.4 kb/s) (average 174.4 kb/s)
    script.sh does not exist
    test.sql and script.sh are in the same directory.


    Thanks

  8. #8
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Even though they are in the same directory, the shell running the cronjob probably cannot find them (b/c they are not in its PATH). Try using full path names to any files referenced in your script called by cron.

    If you want more help, you can post your cron script, too.

  9. #9
    Just Joined!
    Join Date
    Aug 2011
    Location
    FRANCE !
    Posts
    5
    The important part of my script.sh is :

    Code:
    smbclient //192.168.1.xx/onlyuser -A /essais/cred -c "prompt;put test.sql;put script.sh;exit;"
    THe line of my crontab is :
    Code:
     */1  *  *  *  * root /essais/script.sh >> /logsmb.txt 2>&1
    script.sh and test.sql are in the folder :
    /essais/


    When I change "put script.sh" by "put /essais/script.sh" I have this error :
    Code:
    putting file test.sql as \test.sql (111.0 kb/s) (average 111.0 kb/s)
    NT_STATUS_OBJECT_NAME_INVALID opening remote file \/essais/script.sh

  10. #10
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Does script.sh already exist on the samba host? Is it open/in use on the samba host? Are the permissions of it such that it cannot be overwritten?

    I can emulate your setup on my machine and run it perfectly, as far as I can tell.
    Code:
    Domain=[SAMBA_HOST] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]
    putting file test.sql as \test.sql (0.0 kb/s) (average 0.0 kb/s)
    putting file script.sh as \script.sh (49.3 kb/s) (average 24.7 kb/s)

Posting Permissions

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