Cronjob does not work for the local asdf elixir path [closed]

My crontab file looks like:

*/1 * * * * /Users/dmitriy/.asdf/shims/elixir ~/work/scripts/my_script.exs

And that script doesn’t work. As I understand it, cron cannot detect the location of elixir. I run it on macOs Ventura.

How can I solve this problem?

2

I’m on macOS 12.5.1, and I have elixir installed with asdf as well. My path to elixir is the same as yours but with my user name instead:

*/1 * * * * /Users/7stud/.asdf/shims/elixir

I used a full path to my elixir script:

*/1 * * * * /Users/7stud/.asdf/shims/elixir /Users/7stud/elixir_programs/my_prog.ex

my_prog.ex contains:

IO.puts "Cron job just finished"

I redirected the output of stdout and stderr from the elixir script to a log file (>> is append):

*/1 * * * * /Users/7stud/.asdf/shims/elixir /Users/7stud/elixir_programs/my_prog.ex >> /Users/7stud/cron_output.log 2>&1

Here is what I see in cron_output.log:

/Users/7stud/.asdf/installs/elixir/1.16.0-otp-26/bin/elixir: line 247: exec: erl: not found
/Users/7stud/.asdf/installs/elixir/1.16.0-otp-26/bin/elixir: line 247: exec: erl: not found
/Users/7stud/.asdf/installs/elixir/1.16.0-otp-26/bin/elixir: line 247: exec: erl: not found
/Users/7stud/.asdf/installs/elixir/1.16.0-otp-26/bin/elixir: line 247: exec: erl: not found
/Users/7stud/.asdf/installs/elixir/1.16.0-otp-26/bin/elixir: line 247: exec: erl: not found
/Users/7stud/.asdf/installs/elixir/1.16.0-otp-26/bin/elixir: line 247: exec: erl: not found

...
...

It looks like erl, i.e. the erlang command, can’t be found.

I also have python installed with asdf, and it has the same path as elixir but with python instead of the word elixir. Here’s a cron job for python:

*/1 * * * * /Users/7stud/.asdf/shims/python /Users/7stud/python_programs/1.py >> /Users/7stud/cron_output.log 2>&1

Here’s my python program 1.py:

print("Cron job just finished")

Output in cron_output.log:

Cron job just finished
Cron job just finished
Cron job just finished
Cron job just finished
...
...

The interplay between elixir and erlang seems to be the problem with scheduling elixir scripts.

This worked for me:

*/1 * * * * PATH=~/.asdf/shims:$PATH; /Users/7stud/elixir_programs/my_prog.ex >> /Users/7stud/cron_output.log 2>&1

The last part:

>> /Users/7stud/cron_output.log 2>&1

just redirects stdout and stderr to a log file. You don’t have to do that. I get system mail if there are errors when executing the cronjob or if there is unhandled output:

Last login: Mon Feb 26 08:57:10 on ttys009
You have new mail.

~%  mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/mail/7stud": 8 messages 8 new
>N  1 7stud@7studs-MacBook  Mon Feb 26 09:13  18/749   "Cron <7stud@7studs-MacBook-Pro> /bin/bash "
 N  2 7stud@7studs-MacBook  Mon Feb 26 09:14  18/749   "Cron <7stud@7studs-MacBook-Pro> /bin/bash "
 N  3 7stud@7studs-MacBook  Mon Feb 26 09:15  18/749   "Cron <7stud@7studs-MacBook-Pro> /bin/bash "
 N  4 7stud@7studs-MacBook  Mon Feb 26 09:16  18/749   "Cron <7stud@7studs-MacBook-Pro> /bin/bash "
 N  5 7stud@7studs-MacBook  Mon Feb 26 09:16  18/749   "Cron <7stud@7studs-MacBook-Pro> /bin/bash "
 N  6 7stud@7studs-MacBook  Mon Feb 26 09:18  18/745   "Cron <7stud@7studs-MacBook-Pro> /bin/bash "
 N  7 7stud@7studs-MacBook  Mon Feb 26 09:19  18/745   "Cron <7stud@7studs-MacBook-Pro> /bin/bash "
 N  8 7stud@7studs-MacBook  Mon Feb 26 09:19  18/745   "Cron <7stud@7studs-MacBook-Pro> /bin/bash "
? 1
Message 1:
From [email protected]  Mon Feb 26 09:13:01 2024
X-Original-To: 7stud
Delivered-To: [email protected]
From: [email protected] (Cron Daemon)
To: [email protected]
Subject: Cron <7stud@7studs-MacBook-Pro> /bin/bash -lc "elixir /Users/7stud/elixir_programs/my_prog.ex"
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=7stud>
X-Cron-Env: <USER=7stud>
Date: Mon, 26 Feb 2024 09:13:00 -0700 (MST)

/bin/bash: elixir: command not found

You can execute your shell from the crontab, which will pick up the desired environment.

For bash:

*/1 * * * * /bin/bash -lc "elixir ~/work/scripts/my_script.exs"

0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật