Scheduled script to clear proxy cache doesnt work

Hi all

I have several web proxy cache… with this scrpt:

/ip proxy set enable=no
:delay 10s
/ip proxy clear-cache

If I run this script in certains ways I obtain different results.

  1. If I use the “scheduled” mode with the winbox open, then the proxy cache disk (sata in secondary disk) becomes to 0 Kb. This is ok.
  2. If I run manually the script from winbox, then the proxy cache disk (sata in secondary disk) becomes to 0 Kb. This is ok.
  3. If I want to use the scheduled function with the winbox closed, the script runs, BUT the cache disk NOT erase any data, and follows with her previous size.

I want to clear the cache disk for better performance after 7 days in automatic way, but in the scheduled mode the data over the disk follows after the scripts runs at the indicate date.

I revised the permissions and all looks ok… but in scheduled mode with the winbox closed, the sata disk NOT erase the data.

Any idea?

Check if the “run count” of scheduler and of scripts changes.
And check the clock and the “next run” of scheduler.

Good luck

all this items has been checked.

and do they increase, have sane values?

they increased all the time… the proxy follow runs at the scheduled time without problem… this has confirmed on log

but it has no visible effects after the script runs with in scheduled with the winbox closed. (if I run the script manually they clear the disk ok)

the complete script “ClearCache” is here

/ip proxy set enable=no
:delay 10s
/ip proxy clear-cache
:delay 15m
/ip proxy set enable=yes

the scheduler config:

 /system scheduler> pr
Flags: X - disabled 
 #   NAME   START-DATE  START-TIME   INTERVAL             ON-EVENT   RUN-COUNT 
0   Cle... dec/18/2009 14:41:00     1w                   ClearCache 1

the proxy config:

/ip proxy> pr
                 enabled: yes
             src-address: 0.0.0.0
                    port: 3128
            parent-proxy: 0.0.0.0
       parent-proxy-port: 0
     cache-administrator: "webmaster"
          max-cache-size: unlimited
           cache-on-disk: yes
  max-client-connections: 1000
  max-server-connections: 1000
          max-fresh-time: 3d
   serialize-connections: no
       always-from-cache: no
          cache-hit-dscp: 4
             cache-drive: sata1

What version are you running? One thing to check is permissions for the script. Post the output of:

/system scheduler export

You may want to trim that output to just show the specific script

/system scheduler
add comment="" disabled=no interval=1w name=ClearCache on-event=ClearCache \
    policy=reboot,read,write,policy,test,password,sniff,sensitive \
    start-date=jan/01/1970 start-time=05:15:00

Mikrotik V 4.2

Please add:

/system script export

Also, try running (from the CLI):

/system script run ClearCache

From your previous post, it seems that it runs when you do that. Is that correct?

One more thing to try. Run (CLI):

/system scheduler 
set ClearCache policy=ftp,local,password,policy,read,reboot,sensitive,sniff,ssh,telnet,test,web,winbox,write
/system script 
set ClearCache policy=ftp,local,password,policy,read,reboot,sensitive,sniff,ssh,telnet,test,web,winbox,write

That gives both the script and scheduler FULL policy rights. If that makes it work correctly, then you should be able to remove some of the rights one at a time to see which rights are minimum requirements. Note that there are several policy options available in CLI that are NOT configurable in Winbox. These include:

  • ftp
  • local
  • ssh
  • telnet
  • web
  • winbox

Just adjust the above policy configurations via the CLI until you get the right set of rights.

Thank you Butch by your help.

This solution (set full policy rights) has not work. Same results.

This issue really seems a bug. I think.

The script ONLY works ok by run manually within winbox or in CLI. In scheduled run, ONLY works with the winbox session opened with MY EYES put on her. :open_mouth:

BUT If I go sleep (or anything else :slight_smile: ) in scheduled mode with the winbox session CLOSED it doesnt works at all and the size of data in SATA disk is equal to the size previous script run, and after all they follows increase as normal run of the proxy. :frowning:

Here I found something !!

If I run “/system script run ClearCache” in the CLI I need to press “y” (yes) then the scripts REALLY clear the disk and GO to size 0.

See:

/system script run ClearCache
Clear all web proxy cache, yes? [y/N]: 
y
cache will be cleared shortly

Questions:

This can be the problem?

And if yes… How I can put the “y” into the script?

Thanks in advance.

That would be the problem. As far as I know, there’s no way to automatically answer prompts in scripts. Maybe put in a feature request that adds an optional parameter to the command to circumvent the prompt in scripts? Kinda like “/noconfirm” on interactive Cisco IOS commands.

I am looking at another option

I thought there may be another method to do this, but it is not possible. Every option I have tried will run into at least one prompt to confirm an action.