Crontab with sudo command

Hello Manjaro community.

Recently I’m trying to create a routine with CRONTAB to execute, every 1 hour, 2 commands a with privileges;
0 * * * * sudo sync & sudo sysctl vm.drop_caches=3

The problem I’m facing is that…

I edit the file with the command;
crontab -e

Saved, but the commands are not executed.

And I’m having trouble creating with;
sudo crontab -e

Because of the editor that is shown to me, I have no idea how to save the file, in addition to the difficulty in editing the text.

Can anyone help me?
image
Editor image: sudo crontab -e

image
Editor image: crontab -e

You cannot - use a systemd oneshot service and a timer.

But why drop cache every 60m?

You will only slow your filesystem down.

I thought about doing this download because my hardware is a little old.

I have about 8Gb of RAW and the processor is an Intel 3.

Recurrently my system has crashes and “bottlenecks”

I’m not sure if what you are trying is going to help, but in any case, if you are going to do it, don’t use cron with your user, use cron with root. That way you don’t need sudo

1 Like

That sounds more like missing swap or perhaps too litle swap.

I don’t know exactly what could be causing this.

Eventually my system has a completely black screen, the sound keeps coming out, but the system is locked (I check by activating/deactivating NumLock and the light does not turn off).

In fact, the Swap memory is set to 0, could that be the problem?

Try this for editor: sudo -E crontab -e

Worked, thank you

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.