SRE-Docker Compose for CRON job

Discussion in 'Linux Beginners' started by Ashishsme14, Feb 25, 2021.

Tags:
  1. Ashishsme14

    Ashishsme14 New Member

    We had a task to Create a docker file with ubuntu image
    1. Create a print.sh file which has code to print date and time
    2. Write a cron file named "hello-cron" which includes the print.sh to run for every 1 min.
    3. The docker image should have a CRON job to print date and time every 1 min
    We created a print.sh file via vi command and in it given as

    #!/bin/sh -l
    time=$(date)
    echo "::set-output name=time::$time"

    After which we had executed -

    chmod +x print.sh

    then tried as -

    * * * * * /home/scrapbook/tutorial

    Not sure where we went wrong, please guide us.
     
  2. Taleman

    Taleman Well-Known Member HowtoForge Supporter

  3. Ashishsme14

    Ashishsme14 New Member

    Hi,

    I had successfully created print.sh but cannot able to run a cron file with print.sh with a min. Need help for it.
     
  4. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    I am assuming you are using Ubuntu 20.04.
    Put listings and command outputs you post in CODE tags. See https://www.howtoforge.com/community/threads/please-read-before-posting.58408/
    What shows command
    Code:
    crontab -l
    What shows command
    Code:
    ls -lh print.sh
    Put your print.sh file in /tmp directory for testing. Then use command
    Code:
    crontab -e
    to add line
    Code:
    * * * * * /tmp/print.sh
    Do note that unless you have set up cron to e-mail the results to you, your print.sh does nothing visible. I would modify print.sh with adding line
    Code:
    echo $(date) >> /tmp/foobar.txt
    and then see what happens with command
    Code:
    tail -f /tmp/foobar.txt
     
  5. Ashishsme14

    Ashishsme14 New Member

    We execute above command -

    $
    $ crontab -l
    no crontab for root
    $ ls
    $ pwd
    /home/scrapbook/tutorial
    $

    We need to perform -

    Create a docker file with ubuntu image
    • Create a print.sh file which has code to print date and time
    • Write a cron file named "hello-cron" which includes the print.sh to run for every 1 min

    • The docker image should have a CRON job to print date and time every 1 min
     
  6. Ashishsme14

    Ashishsme14 New Member

    plz help us
     
  7. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    I've never used docker, but the command in a crontab should be executable, where it seems you put a directory path.
     
  8. Ashishsme14

    Ashishsme14 New Member

    What will be command in docker ?
     
  9. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    Do you have the docker file with ubuntu image created? Does it work?
    If yes, do the commands I gave in #4 work?
     
  10. Ashishsme14

    Ashishsme14 New Member

    Do you have the docker file with ubuntu image created? Does it work?
    If yes, do the commands I gave in #4 work?

    Does not worked ...

    We need to perform -

    Create a docker file with ubuntu image
    • Create a print.sh file which has code to print date and time
    • Write a cron file named "hello-cron" which includes the print.sh to run for every 1 min
    • The docker image should have a CRON job to print date and time every 1 min
     
  11. Taleman

    Taleman Well-Known Member HowtoForge Supporter

  12. Ashishsme14

    Ashishsme14 New Member

    It not resolved our issue
     

Share This Page