Thursday, June 4, 2020

Clear Dispatcher cache remotely via shell script | Windows BAT script

There are number of ways to clear dispatcher cache- This article talks about how to clear it using batch or shell script.

Read the following article for other options e.g. curl script, replication agent etc.- https://aem6solutions.blogspot.com/2019/11/cache-clearance-in-dispatcher.html

Many times we need to ssh remote servers to run specific linux commands manually. If you have to run it quite often and run the same command on multiple servers doing it manually becomes hectic. Below is sample code which you can use to create a shell script (In Linux) or a Batch program (In Windows).

1. The first file is the executable batch file- I have wrote it for windows but it can be written in shell script for Linux as well.

2. The second file - clear-cache-remote.cmd - lists all the commands that you want to run as a group.

ECHO OFF
CLS
:MENU
ECHO.
ECHO ........................
ECHO SSH servers
ECHO ........................
ECHO.
ECHO 1 - Web Server 1
ECHO 2 - Web Server 2
ECHO 3 - Web Server 3
ECHO 4 - Web Server 4
ECHO E - EXIT
ECHO.
SET /P M=Type 1 - 4 then press ENTER:
IF %M%==1 GOTO WEB1
IF %M%==2 GOTO WEB2
IF %M%==3 GOTO WEB3
IF %M%==4 GOTO WEB4
IF %M%==E GOTO EOF
REM -------------------------------------------------------------------
REM SSH Server details
REM -- Replace xx.xxx.xxx.xxx with your server ip like - 54.213.11.163
REM ------------------------------------------------------------------
:WEB1
CLS
putty.exe -ssh -2 -v -l ssh-user-name -pw mypwd -i "C:\Users\ntuser\.ssh\id_rsa.ppk" -m c:clear-cache-remote.cmd xx.xxx.xxx.xxx
REM -- call ssh ssh-user-name@xx.xxx.xxx.xxx -pw mypwd
:WEB2
CLS
putty.exe -ssh -2 -v -l ssh-user-name -pw mypwd -i "C:\Users\ntuser\.ssh\id_rsa.ppk" -m c:clear-cache-remote.cmd xx.xxx.xxx.xxx
:WEB3
CLS
putty.exe -ssh -2 -v -l ssh-user-name -pw mypwd -i "C:\Users\ntuser\.ssh\id_rsa.ppk" -m c:clear-cache-remote.cmd xx.xxx.xxx.xxx
:WEB4
CLS
putty.exe -ssh -2 -v -l ssh-user-name -pw mypwd -i "C:\Users\ntuser\.ssh\id_rsa.ppk" -m c:clear-cache-remote.cmd xx.xxx.xxx.xx
putty.exe -ssh -2 -v -l ssh-user-name -pw mypwd -i "C:\Users\ntuser\.ssh\id_rsa.ppk" -m c:clear-cache-remote.cmd 54.213.11.163
REM close the command window
cmd /c
echo Remove files under /mnt/var/www/html
sudo rm -rf /mnt/var/www/html/etc.clientlibs
sudo rm -rf /mnt/var/www/html/etc
sudo rm -rf /mnt/var/www/html/content
sudo rm -rf /mnt/var/www/html/services
sudo rm -rf /mnt/var/www/html/config
echo Cache cleared successfully

No comments:

Post a Comment

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps: 1. Develop Custom TransportHandler Develop a custom Trans...