Cron to clean up media files not working

#1

Hi,

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

mastodon@s3:~$ cat media_remove.sh
#!/bin/bash
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/media_remove.sh

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
Chris

#2

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.

#3

Thanks, I’ll try that!

#5

What’s the difference?

1 Like
#6

i shouldn’t be here actually :grimacing:

#7

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:

#!/bin/bash
cd /home/mastodon/live
PATH=/home/mastodon/bin:/home/mastodon/.local/bin:/home/mastodon/.rbenv/plugins/ruby-build/bin:/home/mastodon/.rbenv/shims:/home/mastodon/.rbenv/bin:/usr/bin:/bin
RAILS_ENV=production bin/tootctl media remove > log/media_remove.log 2>&1
1 Like