Skip to content

Instantly share code, notes, and snippets.

@nehabhardwaj01
Last active December 30, 2019 14:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nehabhardwaj01/e991a76b73d640243c3914d480686fa3 to your computer and use it in GitHub Desktop.
Save nehabhardwaj01/e991a76b73d640243c3914d480686fa3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Start the run once job.
echo "Docker container has been started"
# Setup a cron schedule
echo "* * * * * /run.sh >> /var/log/cron.log 2>&1
# This extra line makes it a valid cron" > scheduler.txt
crontab scheduler.txt
cron -f
@peter279k
Copy link

It looks like it misses the " on line 7. And I think the fixed snippets are as follows:

echo "* * * * * /run.sh" >> /var/log/cron.log 2>&1

@peter279k
Copy link

I think the line 7 and line 8 are on the same line. And the snippet should look like:

#!/bin/bash

# Start the run once job.
echo "Docker container has been started"

# Setup a cron schedule
printf "* * * * * /run.sh >> /var/log/cron.log 2>&1\n# This extra line makes it a valid cron" > scheduler.txt

crontab scheduler.txt
cron -f

@nehabhardwaj01
Copy link
Author

@peter279k Yes, it can be rewritten in a single line as you suggested. The only difference is the former one serves better clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment