saggit
Hi, everybody
I was try to use crontab to schedule my simple mix task that send emails, the task works perfect by run
mix hello.greeting but does not work (scheduled, but no email sent ) if i put something like this in crontab */5 * * * * cd path/to/myapp; /usr/local/bin/mix hello.greeting
my simple task code
defmodule Mix.Tasks.Hello.Greeting do
use Mix.Task
alias Hwapp.Email
alias Hwapp.Mailer
@shortdoc "Sends a greeting to us from Hello Phoenix"
@moduledoc """
This is where we would put any long form documentation or doctests.
"""
def run(_args) do
Mix.shell.info("Greetings from the Hello Phoenix Application!")
Mix.Task.run "app.start"
# get all users
"hello@localhost"
Email.welcome_html_email()
|> Mailer.deliver_now
end)
end
end
Thanks for your time.
Trending in Questions
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #elixirconf-us
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance











Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
speeddragon
You can put that code
cd path/to/myapp; /usr/local/bin/mix hello.greetinginside a shell script (something.sh) give +x permission (chmod +x something.sh) and then call it on the crontab. Don’t forget to use full path instead of relative paths.saggit
Thanks for your reply, I tried and got the same result, Just wonder if I got something wrong.
NobbZ
Does cron send you any logs? If not please activate the feature to send you the logs of each run to your local address for the debugging period at least(*).
Also, how are you editing your crontab? If you do not use
crontab -e(*) Cron won’t know about the changes and nothing will be run of course.Have you made sure that the project folder and all folders above and below and the files are actually readable/accessible by the user that owns the crontab in question?
(*): Can’t look up details or exact command as I’m on mobile right now.
saggit
Hi Nobbz, Thanks for your reply,
tail -f /var/log/cron.loggive me correct execute log say every 5 minutes without error message so that mean the path are correct and command run without error. I have to do more check. But thanks.NobbZ
As far as I remember Cron log will only contain that a job has started, it will not contain it’s results. Please try writing into a file, use the wrapper script from before and change it to be like this:
speeddragon
Finally got it working. Here is the steps done in my computer (running OSX), it might change a little bit if you use Linux.
I’ve created a script with the following code:
And run with the following line on crontab:
The output of crontab.log was showing this:
Using the full path of
mixdidn’t solve it. (/usr/local/bin/mix phx.server)Searching that on google, I found an comment from José Valim, Ability to use elixir commands that shipped as an application dependency · Issue #789 · elixir-lang/elixir · GitHub
But even using
/usr/local/bin/elixir /usr/local/bin/mix phx.server &didn’t solve it, because it gave the following error:So, if you output the $PATH, you will see that only have 2 directories (or less than you expected):
/usr/bin:/binYou can check where is your binaries, with the command
which, likewhich elixir. You will need in your path at least formix,elixiranderl.In the final script, you should export PATH concatenating the missing path, in my case was
/usr/local/bin/.After that you should be able to run any command with
mix, you don’t need the full path.saggit
It works perfect, thanks for your help,
Really wonderful community.
saggit
Thanks Nobbz,