CE - seaf-gc.sh non running in crontab

Hi there, I’ve found a strange issue, maybe somebody has solved it.

I need to run seaf-gc.sh often, because my library sync a huge file that keeps evolving.

Now if I run seaf-gc.sh either manually with user seafile and from the script (posted below) with user root it runs great and frees the space I need.
But if I run it in crontab (root crontab) it doesn’t run.

Here is the cronjob I run:
0 1 * * * /script/seafile_cleanup.sh

And the seafile_cleanup.sh script:


echo "Registering space BEFORE script"
echo "BEFORE" >> /script/seafile_cleanup.sh.log
date >> /script/seafile_cleanup.sh.log
df -h /dev/vda >> /script/seafile_cleanup.sh.log

service seafile-server stop
sleep 20

su seafile -c "/home/seafile/seafile-server-latest/seaf-gc.sh"
sleep 10

service seafile-server start
echo "Registering space AFTER script..."
echo "AFTER" >> /script/seafile_cleanup.sh.log
date >> /script/seafile_cleanup.sh.log
df -h /dev/vda >> /script/seafile_cleanup.sh.log

echo "" >> /script/seafile_cleanup.sh.log
echo "" >> /script/seafile_cleanup.sh.log

Any help please?

Chmod x+


The script is run by root user which has permission to execute.

 ll /script/seafile_cleanup.sh
-rwxr--r-- 1 root root 1067 Apr 15 09:37 /script/seafile_cleanup.sh*

Looks fine to me.

The folder script is in root? (/scripts)

Try to execute the script with ... ** bash /scripts/seaf...

1 Like

I’ll try it.

Nope, it’s not working. Maybe it has to deal with env variables that may differ when used in cron, I’ll investigate

Ok the problem where environment variables which are different from system and cron. I’ll post the solution in case it could help others.

You have to tell cron to use correct variables by putting them in the script directly or in crontab itself (and it will work for all cronjobs).

Cool. Could you give an example how you extended the script(s) to work properly?
I was thinking of writing a systemd unit to execute gc and have it start and stop properly.
But currently I have no time for seafile CE work.

The script is the same, I just edited crontab to make it work. I added this line in crontab (root)


taken from my env.

If you type env you’ll see the corresponding path of your system (which might differ from system to system).
This is just a crontab issue, since many bash scripts doesn’t work in crontab, but with this fix they should.