Hi,
I'm trying to create a cronjob to run every minute to drop cache checking a certain condition to be met and i don't want them to overlap if it takes too long so i tried using flock. The cronjob checks if the used ram percentage is less than given value and used ram+cache ram percentage is more than given value then executes. It's like this:
So after enabling this, every minute i got an email like this one below:
/bin/sh: 1: cannot open 465000: No such file
/bin/sh: 1: 455583: not found
When i run the command manually from cli it works fine, when it's a cronjob this happens. Can someone help please? The very same code works fine with other linux os types like centos or ubuntu is it something about debian?
Edit:
I also tried the same with a single ping command to run for 300 seconds every minute with flock and it seems to work fine.Cronjob:
Output:
But doesnt work with the drop cache command.
I'm trying to create a cronjob to run every minute to drop cache checking a certain condition to be met and i don't want them to overlap if it takes too long so i tried using flock. The cronjob checks if the used ram percentage is less than given value and used ram+cache ram percentage is more than given value then executes. It's like this:
Code:
* * * * * flock -n /tmp/cache.lock -c "if (( $(free -m | grep Mem | awk '{print $3/$2 * 10000000}') < 465000 )) && (( $(free -m | grep Mem | awk '{print ($3+$6)/$2 * 10000000}') > 465000 )); then sync; echo 3 > /proc/sys/vm/drop_caches; fi"
So after enabling this, every minute i got an email like this one below:
/bin/sh: 1: cannot open 465000: No such file
/bin/sh: 1: 455583: not found
When i run the command manually from cli it works fine, when it's a cronjob this happens. Can someone help please? The very same code works fine with other linux os types like centos or ubuntu is it something about debian?
Edit:
I also tried the same with a single ping command to run for 300 seconds every minute with flock and it seems to work fine.Cronjob:
Code:
* * * * * flock -n /tmp/ping.lock -c "timeout 300 ping 8.8.8.8"
Output:
Code:
fuser -v /tmp/ping.lock
USER PID ACCESS COMMAND
/tmp/ping.lock: root 54422 f.... flock
root 54423 f.... sh
root 54425 f.... timeout
root 54426 f.... ping
But doesnt work with the drop cache command.
Last edited: