#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0

    Script shell working manually, but not with cron


    Hi,

    I just did a script in the purpose to save all directory from a specific one's (/var/www/html ).
    The script works perfectly when launched manually, but not at all when it's the cron that launch it automatically =/

    here's the script =>

    Code:
    for SITE in `ls $MYDIR | grep -v "chroot\|default"` ; do
    if [ -d $MYDIR${SITE} ]; then
    echo 'here, before tar '$MYDIR${SITE} >> log.txt
    tar -czvf ./${SITE}.tar.gz $MYDIR${SITE}
    fi
    done


    I just have no idea what's going on, i checked into the log.txt, the path and the directory name are good, but, it looks like only one directory has been zipped, and nothing else happen,...

    Here's what i got from the log =>
    Quote:
    here, before tar /var/www/html/my_sitename


    Hoping someone could give me a hint on this issue,

    Hurin

    PS: sorry for my low english level ^^
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,447
    Rep Power
    1751
    A couple of things spring to mind - the environment in use (there are differences between your user environment and the one cron providesn - maily in PATH but also in what shell is used). Where does the variable $MYDIR come from?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0

    Smile


    Ok, i just found out how to make it work, even if i don't understand why, but the fact to redirect the output of the command tar -czvf has been enough to make it work 0_o
    So, before, i had this =>
    tar -czvf ./${SITE}.tar.gz $MYDIR${SITE}

    And now, i got this =>
    tar -czvf ./${SITE}.tar.gz $MYDIR${SITE} >> log.txt 2>&1

    So, if anyone know why it's working now, i would gladly learn it from him
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,447
    Rep Power
    1751
    No idea why appending the stdout and stderr from the tar command is now making the (I presume) loop process more directories! What happens if you run the revised script manually?

    <edit>
    Now, having tried the code (and giving MYDIR a suitable value), I can really see no reason as the original code works fine for me - both run manually and via cron.
    </edit>
    Last edited by SimonJM; April 18th, 2013 at 08:15 AM.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo