I have a sh script. How to run it using crontab?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have the following file execute-backup-from-container.sh. The content of this file is:



#!/bin/bash
FILE=minime.sql.`date +"%Y%m%d".gz`
CONTAINER='mysql_01'
SCRIPT_ON_CONTAINER='/container-mysql-dump.sh'

$OUTPUT=$(docker exec $CONTAINER /$SCRIPT_ON_CONTAINER)

echo "=============="
echo "$CONTAINER:/$FILE"
echo "=============="
docker cp "$CONTAINER:/$FILE" backup-data/


When I run crontab -e I am putting the following:
0 5 * * 1 /home/me/projects/execute-backup-from-container.sh
This means that the execute-backup-from-container.sh should be executed every day at 5:00 am.

The problem is that the script is not executed at all.

So what on earth is the problem? Why is it not executed?







share|improve this question




















  • @steeldriver you are right. If I want to make it every day should I have to put * instead of 1?
    – Cristian
    Mar 23 at 23:52










  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Mar 25 at 19:01






  • 1




    Also, you have a syntax error in the script: $OUTPUT=... should just be OUTPUT=...
    – Jeff Schaller
    Mar 27 at 12:38














up vote
1
down vote

favorite












I have the following file execute-backup-from-container.sh. The content of this file is:



#!/bin/bash
FILE=minime.sql.`date +"%Y%m%d".gz`
CONTAINER='mysql_01'
SCRIPT_ON_CONTAINER='/container-mysql-dump.sh'

$OUTPUT=$(docker exec $CONTAINER /$SCRIPT_ON_CONTAINER)

echo "=============="
echo "$CONTAINER:/$FILE"
echo "=============="
docker cp "$CONTAINER:/$FILE" backup-data/


When I run crontab -e I am putting the following:
0 5 * * 1 /home/me/projects/execute-backup-from-container.sh
This means that the execute-backup-from-container.sh should be executed every day at 5:00 am.

The problem is that the script is not executed at all.

So what on earth is the problem? Why is it not executed?







share|improve this question




















  • @steeldriver you are right. If I want to make it every day should I have to put * instead of 1?
    – Cristian
    Mar 23 at 23:52










  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Mar 25 at 19:01






  • 1




    Also, you have a syntax error in the script: $OUTPUT=... should just be OUTPUT=...
    – Jeff Schaller
    Mar 27 at 12:38












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have the following file execute-backup-from-container.sh. The content of this file is:



#!/bin/bash
FILE=minime.sql.`date +"%Y%m%d".gz`
CONTAINER='mysql_01'
SCRIPT_ON_CONTAINER='/container-mysql-dump.sh'

$OUTPUT=$(docker exec $CONTAINER /$SCRIPT_ON_CONTAINER)

echo "=============="
echo "$CONTAINER:/$FILE"
echo "=============="
docker cp "$CONTAINER:/$FILE" backup-data/


When I run crontab -e I am putting the following:
0 5 * * 1 /home/me/projects/execute-backup-from-container.sh
This means that the execute-backup-from-container.sh should be executed every day at 5:00 am.

The problem is that the script is not executed at all.

So what on earth is the problem? Why is it not executed?







share|improve this question












I have the following file execute-backup-from-container.sh. The content of this file is:



#!/bin/bash
FILE=minime.sql.`date +"%Y%m%d".gz`
CONTAINER='mysql_01'
SCRIPT_ON_CONTAINER='/container-mysql-dump.sh'

$OUTPUT=$(docker exec $CONTAINER /$SCRIPT_ON_CONTAINER)

echo "=============="
echo "$CONTAINER:/$FILE"
echo "=============="
docker cp "$CONTAINER:/$FILE" backup-data/


When I run crontab -e I am putting the following:
0 5 * * 1 /home/me/projects/execute-backup-from-container.sh
This means that the execute-backup-from-container.sh should be executed every day at 5:00 am.

The problem is that the script is not executed at all.

So what on earth is the problem? Why is it not executed?









share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 23:46









Cristian

265212




265212











  • @steeldriver you are right. If I want to make it every day should I have to put * instead of 1?
    – Cristian
    Mar 23 at 23:52










  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Mar 25 at 19:01






  • 1




    Also, you have a syntax error in the script: $OUTPUT=... should just be OUTPUT=...
    – Jeff Schaller
    Mar 27 at 12:38
















  • @steeldriver you are right. If I want to make it every day should I have to put * instead of 1?
    – Cristian
    Mar 23 at 23:52










  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Mar 25 at 19:01






  • 1




    Also, you have a syntax error in the script: $OUTPUT=... should just be OUTPUT=...
    – Jeff Schaller
    Mar 27 at 12:38















@steeldriver you are right. If I want to make it every day should I have to put * instead of 1?
– Cristian
Mar 23 at 23:52




@steeldriver you are right. If I want to make it every day should I have to put * instead of 1?
– Cristian
Mar 23 at 23:52












If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
– Jeff Schaller
Mar 25 at 19:01




If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
– Jeff Schaller
Mar 25 at 19:01




1




1




Also, you have a syntax error in the script: $OUTPUT=... should just be OUTPUT=...
– Jeff Schaller
Mar 27 at 12:38




Also, you have a syntax error in the script: $OUTPUT=... should just be OUTPUT=...
– Jeff Schaller
Mar 27 at 12:38










3 Answers
3






active

oldest

votes

















up vote
4
down vote













The cron fields corresponding to your entry mean:



minute: 0 
hour: 5
day of month: *
month: *
day of week: 1
command: /home/me/projects/execute-backup-from-container.sh


which translate in English to: Mondays at 5am (any day of the month, any month).



If you want it to be executed:




every day at 5:00 am




then you want that 5th field to be a *:



0 5 * * * /home/me/projects/execute-backup-from-container.sh





share|improve this answer






















  • good point there. I modified the 1 into * to be executed every day of the week, but still does not execute the script.
    – Cristian
    Mar 27 at 12:36










  • is there a cron error message in the logs? Is the script executable?
    – Jeff Schaller
    Mar 27 at 12:37










  • No, there are no error messages in the logs. I have read the logs with ` grep CRON /var/log/syslog`
    – Cristian
    Mar 27 at 16:34

















up vote
1
down vote













Did you check that the file is set to be executable? Here is an example of marking a script as executable:



$ ls -l test.sh
-rw-r--r-- 1 ahill ahill 0 Mar 23 19:30 test.sh
$ chmod +x test.sh
$ ls -l test.sh
-rwxr-xr-x 1 ahill ahill 0 Mar 23 19:30 test.sh


The next thing to check is the environment. cron jobs inherit no environment by default. The "fix" is discussed here:
How can I run a cron command with existing environmental variables?



One of the reasons that the environment is a big deal is that cron might not even find bash! see: https://www.digitalocean.com/community/questions/why-is-cron-not-running-my-sh-script



If you still cannot figure it out, I would do a test: Change your cron job from:



0 5 * * * /home/me/projects/execute-backup-from-container.sh


to:



0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 


What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, though the file does not need to.)



I also noticed something in the OP that might be the real problem: the word "container." If the script is inside of a Docker container, then this is likely the solution:
https://www.ekito.fr/people/run-a-cron-job-with-docker/






share|improve this answer






















  • This answer misses the point that the schedule used in the crontab is wrong.
    – Kusalananda
    Mar 24 at 15:29










  • You right... should have looked at that first... but I will leave it here as it might help someone else that is searching.
    – Art Hill
    Mar 26 at 15:06










  • Good point with the permissions. I had already put 777 to execute-backup-from-container.sh file before posting the question, so it does not help that, but I will check the environment variable solution and let you know.
    – Cristian
    Mar 27 at 12:38











  • So I have used the following environment variables but still not working: HOME=/home/cristian LOGNAME=cristian PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin SHELL=/bin/bash PWD=/home/cristian BASH_ENV=/home/cristian/.profile
    – Cristian
    Mar 27 at 17:08







  • 1




    I would do a test: Change your cron job from: 0 5 * * * /home/me/projects/execute-backup-from-container.sh to: 0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, but he file does not need to.)
    – Art Hill
    Mar 28 at 22:34


















up vote
0
down vote













After keeping into account all the answers, the last issue was in the last line:



docker cp "$CONTAINER:/$FILE" backup-data/ 


The last line should have been



docker cp "$CONTAINER:/$FILE" docker-projects/mysql/backup-data/ 


Thank you all for your support.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433179%2fi-have-a-sh-script-how-to-run-it-using-crontab%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote













    The cron fields corresponding to your entry mean:



    minute: 0 
    hour: 5
    day of month: *
    month: *
    day of week: 1
    command: /home/me/projects/execute-backup-from-container.sh


    which translate in English to: Mondays at 5am (any day of the month, any month).



    If you want it to be executed:




    every day at 5:00 am




    then you want that 5th field to be a *:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh





    share|improve this answer






















    • good point there. I modified the 1 into * to be executed every day of the week, but still does not execute the script.
      – Cristian
      Mar 27 at 12:36










    • is there a cron error message in the logs? Is the script executable?
      – Jeff Schaller
      Mar 27 at 12:37










    • No, there are no error messages in the logs. I have read the logs with ` grep CRON /var/log/syslog`
      – Cristian
      Mar 27 at 16:34














    up vote
    4
    down vote













    The cron fields corresponding to your entry mean:



    minute: 0 
    hour: 5
    day of month: *
    month: *
    day of week: 1
    command: /home/me/projects/execute-backup-from-container.sh


    which translate in English to: Mondays at 5am (any day of the month, any month).



    If you want it to be executed:




    every day at 5:00 am




    then you want that 5th field to be a *:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh





    share|improve this answer






















    • good point there. I modified the 1 into * to be executed every day of the week, but still does not execute the script.
      – Cristian
      Mar 27 at 12:36










    • is there a cron error message in the logs? Is the script executable?
      – Jeff Schaller
      Mar 27 at 12:37










    • No, there are no error messages in the logs. I have read the logs with ` grep CRON /var/log/syslog`
      – Cristian
      Mar 27 at 16:34












    up vote
    4
    down vote










    up vote
    4
    down vote









    The cron fields corresponding to your entry mean:



    minute: 0 
    hour: 5
    day of month: *
    month: *
    day of week: 1
    command: /home/me/projects/execute-backup-from-container.sh


    which translate in English to: Mondays at 5am (any day of the month, any month).



    If you want it to be executed:




    every day at 5:00 am




    then you want that 5th field to be a *:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh





    share|improve this answer














    The cron fields corresponding to your entry mean:



    minute: 0 
    hour: 5
    day of month: *
    month: *
    day of week: 1
    command: /home/me/projects/execute-backup-from-container.sh


    which translate in English to: Mondays at 5am (any day of the month, any month).



    If you want it to be executed:




    every day at 5:00 am




    then you want that 5th field to be a *:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 24 at 13:55

























    answered Mar 24 at 0:49









    Jeff Schaller

    31.2k846105




    31.2k846105











    • good point there. I modified the 1 into * to be executed every day of the week, but still does not execute the script.
      – Cristian
      Mar 27 at 12:36










    • is there a cron error message in the logs? Is the script executable?
      – Jeff Schaller
      Mar 27 at 12:37










    • No, there are no error messages in the logs. I have read the logs with ` grep CRON /var/log/syslog`
      – Cristian
      Mar 27 at 16:34
















    • good point there. I modified the 1 into * to be executed every day of the week, but still does not execute the script.
      – Cristian
      Mar 27 at 12:36










    • is there a cron error message in the logs? Is the script executable?
      – Jeff Schaller
      Mar 27 at 12:37










    • No, there are no error messages in the logs. I have read the logs with ` grep CRON /var/log/syslog`
      – Cristian
      Mar 27 at 16:34















    good point there. I modified the 1 into * to be executed every day of the week, but still does not execute the script.
    – Cristian
    Mar 27 at 12:36




    good point there. I modified the 1 into * to be executed every day of the week, but still does not execute the script.
    – Cristian
    Mar 27 at 12:36












    is there a cron error message in the logs? Is the script executable?
    – Jeff Schaller
    Mar 27 at 12:37




    is there a cron error message in the logs? Is the script executable?
    – Jeff Schaller
    Mar 27 at 12:37












    No, there are no error messages in the logs. I have read the logs with ` grep CRON /var/log/syslog`
    – Cristian
    Mar 27 at 16:34




    No, there are no error messages in the logs. I have read the logs with ` grep CRON /var/log/syslog`
    – Cristian
    Mar 27 at 16:34












    up vote
    1
    down vote













    Did you check that the file is set to be executable? Here is an example of marking a script as executable:



    $ ls -l test.sh
    -rw-r--r-- 1 ahill ahill 0 Mar 23 19:30 test.sh
    $ chmod +x test.sh
    $ ls -l test.sh
    -rwxr-xr-x 1 ahill ahill 0 Mar 23 19:30 test.sh


    The next thing to check is the environment. cron jobs inherit no environment by default. The "fix" is discussed here:
    How can I run a cron command with existing environmental variables?



    One of the reasons that the environment is a big deal is that cron might not even find bash! see: https://www.digitalocean.com/community/questions/why-is-cron-not-running-my-sh-script



    If you still cannot figure it out, I would do a test: Change your cron job from:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh


    to:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 


    What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, though the file does not need to.)



    I also noticed something in the OP that might be the real problem: the word "container." If the script is inside of a Docker container, then this is likely the solution:
    https://www.ekito.fr/people/run-a-cron-job-with-docker/






    share|improve this answer






















    • This answer misses the point that the schedule used in the crontab is wrong.
      – Kusalananda
      Mar 24 at 15:29










    • You right... should have looked at that first... but I will leave it here as it might help someone else that is searching.
      – Art Hill
      Mar 26 at 15:06










    • Good point with the permissions. I had already put 777 to execute-backup-from-container.sh file before posting the question, so it does not help that, but I will check the environment variable solution and let you know.
      – Cristian
      Mar 27 at 12:38











    • So I have used the following environment variables but still not working: HOME=/home/cristian LOGNAME=cristian PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin SHELL=/bin/bash PWD=/home/cristian BASH_ENV=/home/cristian/.profile
      – Cristian
      Mar 27 at 17:08







    • 1




      I would do a test: Change your cron job from: 0 5 * * * /home/me/projects/execute-backup-from-container.sh to: 0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, but he file does not need to.)
      – Art Hill
      Mar 28 at 22:34















    up vote
    1
    down vote













    Did you check that the file is set to be executable? Here is an example of marking a script as executable:



    $ ls -l test.sh
    -rw-r--r-- 1 ahill ahill 0 Mar 23 19:30 test.sh
    $ chmod +x test.sh
    $ ls -l test.sh
    -rwxr-xr-x 1 ahill ahill 0 Mar 23 19:30 test.sh


    The next thing to check is the environment. cron jobs inherit no environment by default. The "fix" is discussed here:
    How can I run a cron command with existing environmental variables?



    One of the reasons that the environment is a big deal is that cron might not even find bash! see: https://www.digitalocean.com/community/questions/why-is-cron-not-running-my-sh-script



    If you still cannot figure it out, I would do a test: Change your cron job from:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh


    to:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 


    What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, though the file does not need to.)



    I also noticed something in the OP that might be the real problem: the word "container." If the script is inside of a Docker container, then this is likely the solution:
    https://www.ekito.fr/people/run-a-cron-job-with-docker/






    share|improve this answer






















    • This answer misses the point that the schedule used in the crontab is wrong.
      – Kusalananda
      Mar 24 at 15:29










    • You right... should have looked at that first... but I will leave it here as it might help someone else that is searching.
      – Art Hill
      Mar 26 at 15:06










    • Good point with the permissions. I had already put 777 to execute-backup-from-container.sh file before posting the question, so it does not help that, but I will check the environment variable solution and let you know.
      – Cristian
      Mar 27 at 12:38











    • So I have used the following environment variables but still not working: HOME=/home/cristian LOGNAME=cristian PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin SHELL=/bin/bash PWD=/home/cristian BASH_ENV=/home/cristian/.profile
      – Cristian
      Mar 27 at 17:08







    • 1




      I would do a test: Change your cron job from: 0 5 * * * /home/me/projects/execute-backup-from-container.sh to: 0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, but he file does not need to.)
      – Art Hill
      Mar 28 at 22:34













    up vote
    1
    down vote










    up vote
    1
    down vote









    Did you check that the file is set to be executable? Here is an example of marking a script as executable:



    $ ls -l test.sh
    -rw-r--r-- 1 ahill ahill 0 Mar 23 19:30 test.sh
    $ chmod +x test.sh
    $ ls -l test.sh
    -rwxr-xr-x 1 ahill ahill 0 Mar 23 19:30 test.sh


    The next thing to check is the environment. cron jobs inherit no environment by default. The "fix" is discussed here:
    How can I run a cron command with existing environmental variables?



    One of the reasons that the environment is a big deal is that cron might not even find bash! see: https://www.digitalocean.com/community/questions/why-is-cron-not-running-my-sh-script



    If you still cannot figure it out, I would do a test: Change your cron job from:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh


    to:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 


    What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, though the file does not need to.)



    I also noticed something in the OP that might be the real problem: the word "container." If the script is inside of a Docker container, then this is likely the solution:
    https://www.ekito.fr/people/run-a-cron-job-with-docker/






    share|improve this answer














    Did you check that the file is set to be executable? Here is an example of marking a script as executable:



    $ ls -l test.sh
    -rw-r--r-- 1 ahill ahill 0 Mar 23 19:30 test.sh
    $ chmod +x test.sh
    $ ls -l test.sh
    -rwxr-xr-x 1 ahill ahill 0 Mar 23 19:30 test.sh


    The next thing to check is the environment. cron jobs inherit no environment by default. The "fix" is discussed here:
    How can I run a cron command with existing environmental variables?



    One of the reasons that the environment is a big deal is that cron might not even find bash! see: https://www.digitalocean.com/community/questions/why-is-cron-not-running-my-sh-script



    If you still cannot figure it out, I would do a test: Change your cron job from:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh


    to:



    0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 


    What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, though the file does not need to.)



    I also noticed something in the OP that might be the real problem: the word "container." If the script is inside of a Docker container, then this is likely the solution:
    https://www.ekito.fr/people/run-a-cron-job-with-docker/







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 28 at 22:44

























    answered Mar 24 at 0:38









    Art Hill

    614




    614











    • This answer misses the point that the schedule used in the crontab is wrong.
      – Kusalananda
      Mar 24 at 15:29










    • You right... should have looked at that first... but I will leave it here as it might help someone else that is searching.
      – Art Hill
      Mar 26 at 15:06










    • Good point with the permissions. I had already put 777 to execute-backup-from-container.sh file before posting the question, so it does not help that, but I will check the environment variable solution and let you know.
      – Cristian
      Mar 27 at 12:38











    • So I have used the following environment variables but still not working: HOME=/home/cristian LOGNAME=cristian PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin SHELL=/bin/bash PWD=/home/cristian BASH_ENV=/home/cristian/.profile
      – Cristian
      Mar 27 at 17:08







    • 1




      I would do a test: Change your cron job from: 0 5 * * * /home/me/projects/execute-backup-from-container.sh to: 0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, but he file does not need to.)
      – Art Hill
      Mar 28 at 22:34

















    • This answer misses the point that the schedule used in the crontab is wrong.
      – Kusalananda
      Mar 24 at 15:29










    • You right... should have looked at that first... but I will leave it here as it might help someone else that is searching.
      – Art Hill
      Mar 26 at 15:06










    • Good point with the permissions. I had already put 777 to execute-backup-from-container.sh file before posting the question, so it does not help that, but I will check the environment variable solution and let you know.
      – Cristian
      Mar 27 at 12:38











    • So I have used the following environment variables but still not working: HOME=/home/cristian LOGNAME=cristian PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin SHELL=/bin/bash PWD=/home/cristian BASH_ENV=/home/cristian/.profile
      – Cristian
      Mar 27 at 17:08







    • 1




      I would do a test: Change your cron job from: 0 5 * * * /home/me/projects/execute-backup-from-container.sh to: 0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, but he file does not need to.)
      – Art Hill
      Mar 28 at 22:34
















    This answer misses the point that the schedule used in the crontab is wrong.
    – Kusalananda
    Mar 24 at 15:29




    This answer misses the point that the schedule used in the crontab is wrong.
    – Kusalananda
    Mar 24 at 15:29












    You right... should have looked at that first... but I will leave it here as it might help someone else that is searching.
    – Art Hill
    Mar 26 at 15:06




    You right... should have looked at that first... but I will leave it here as it might help someone else that is searching.
    – Art Hill
    Mar 26 at 15:06












    Good point with the permissions. I had already put 777 to execute-backup-from-container.sh file before posting the question, so it does not help that, but I will check the environment variable solution and let you know.
    – Cristian
    Mar 27 at 12:38





    Good point with the permissions. I had already put 777 to execute-backup-from-container.sh file before posting the question, so it does not help that, but I will check the environment variable solution and let you know.
    – Cristian
    Mar 27 at 12:38













    So I have used the following environment variables but still not working: HOME=/home/cristian LOGNAME=cristian PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin SHELL=/bin/bash PWD=/home/cristian BASH_ENV=/home/cristian/.profile
    – Cristian
    Mar 27 at 17:08





    So I have used the following environment variables but still not working: HOME=/home/cristian LOGNAME=cristian PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin SHELL=/bin/bash PWD=/home/cristian BASH_ENV=/home/cristian/.profile
    – Cristian
    Mar 27 at 17:08





    1




    1




    I would do a test: Change your cron job from: 0 5 * * * /home/me/projects/execute-backup-from-container.sh to: 0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, but he file does not need to.)
    – Art Hill
    Mar 28 at 22:34





    I would do a test: Change your cron job from: 0 5 * * * /home/me/projects/execute-backup-from-container.sh to: 0 5 * * * /home/me/projects/execute-backup-from-container.sh >> ~/script_errors.log 2>&1 What will happen: the next time cron launches the job, error messages produced will be dumped into the text file script_errors.log. (change the path to the script_errors.log file to whatever seems appropriate, but make sure the path exists, but he file does not need to.)
    – Art Hill
    Mar 28 at 22:34











    up vote
    0
    down vote













    After keeping into account all the answers, the last issue was in the last line:



    docker cp "$CONTAINER:/$FILE" backup-data/ 


    The last line should have been



    docker cp "$CONTAINER:/$FILE" docker-projects/mysql/backup-data/ 


    Thank you all for your support.






    share|improve this answer
























      up vote
      0
      down vote













      After keeping into account all the answers, the last issue was in the last line:



      docker cp "$CONTAINER:/$FILE" backup-data/ 


      The last line should have been



      docker cp "$CONTAINER:/$FILE" docker-projects/mysql/backup-data/ 


      Thank you all for your support.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        After keeping into account all the answers, the last issue was in the last line:



        docker cp "$CONTAINER:/$FILE" backup-data/ 


        The last line should have been



        docker cp "$CONTAINER:/$FILE" docker-projects/mysql/backup-data/ 


        Thank you all for your support.






        share|improve this answer












        After keeping into account all the answers, the last issue was in the last line:



        docker cp "$CONTAINER:/$FILE" backup-data/ 


        The last line should have been



        docker cp "$CONTAINER:/$FILE" docker-projects/mysql/backup-data/ 


        Thank you all for your support.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 30 at 13:47









        Cristian

        265212




        265212






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433179%2fi-have-a-sh-script-how-to-run-it-using-crontab%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?