#!/usr/bin/perl print "===== Flush DNS Cache =====\n"; # The Premise: use sudoedit and other black magic to clear out the memory- # based disk cache (which is done by writing the number 3 to a certain # system file) print " - Synching file system... "; `sync`; print "Done\n"; print " - Dropping memory disk cache... "; # - save our current default editor my $current_editor = $ENV{'EDITOR'}; # - replace default editor with a script that simply clobbers the contents # of any file it's handed with the number "3" $ENV{'EDITOR'} = 'reset_memcache_editor.sh'; # - we now call sudoedit on the system file. How sudoedit works is that it # starts by making a temp copy of the system file with appropriate # permissions allowing the user to edit. It then passes the path to the # temp file to the default editor - typically this would be an interactive # editor like 'vi'. However, we've just replaced the editor with a custom # script that just writes '3' as the content of the tmp file. Finally, when # the editor exits, sudoedit copies the tmp file over the top of the system # file, restoring appropriate root-level permissions `sudoedit /proc/sys/vm/drop_caches`; # - restore the default editor, just in case something in Greenstone # depends on this being a reasonably value $ENV{'EDITOR'} = $current_editor; print "Done\n"; # - short break to give OS time to actually notice the drop_caches command print " - Waiting for command to complete... "; sleep(5); print "Done\n"; print "Complete!\n\n"; exit;