Cron to clean up media files not working



I wrote a little script which uses tootctl to remove media files:

mastodon@s3:~$ cat
cd /home/mastodon/live
RAILS_ENV=production bin/tootctl media remove > log/media_remove.log 2>&1

When I run that script as user mastodon from the command line, it works fine. However, I wanted to run it as a cron job every night:

mastodon@s3:~$ crontab -l
0 5 * * * /home/mastodon/

Unfortunally, that doesn’t work. My log file says:

mastodon@s3:~$ cat live/log/media_remove.log
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler/setup (LoadError)
        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from /home/mastodon/live/config/boot.rb:3:in `<top (required)>'
        from bin/tootctl:3:in `require_relative'
        from bin/tootctl:3:in `<main>'

I don’t know, what that error means and how to fix it. Can someone help me with that?

Thanks and kind regards


Can you add env to your log like this:

and compare your environment differences between manual and automated run.
There will be differences, but some of them may give a clue.


Thanks, I’ll try that!


What’s the difference?

1 Like

i shouldn’t be here actually :grimacing:


Meanwhile, I have solved the problem. :slight_smile: I tested something around and it came out that my instance at cronjob uses the globally installed ruby, not the local one in the user directory. I then adjusted the PATH variable in the script to force it to use the local version. Now it worked :slight_smile: Let’s see if that stays that way:

cd /home/mastodon/live
RAILS_ENV=production bin/tootctl media remove > log/media_remove.log 2>&1
1 Like