Running a script on multiple machines

To clear the web cache on my web server, I run this command:

find $APACHE_HOME/cache/plsql/plsql -type d -name "[0-9]*" -exec rm -R {} \;

To clear the cache on all the web servers(we have 4), I log on to any one machine, clear its cache, ssh to another machine, clear cache etc;

Is there any way to write a script so that this operation can be performed in one script ?

In other words, the script automatically ssh's into the 2nd server, clears the cache and then logs on to 3rd server and so on.

The ssh is over a trusted network and I am using the same account on each of these boxes so I am not prompted for password when going from one machine to another.

I tried to write such a script but what happens is although it logs into the other machine, I see a prompt for the other machine and when I exit it, I am back to the original machine. The script then runs on the original machine.

The shell is ksh and the OS is Solaris 2.8.

Thanx

Looks lke u might have set some environtal variables...

If you wanted to use a script, then you just need to put the command in the script in the format of the ssh command -

ssh [-l login_name] hostname | user@hostname [command]

#!/bin/ksh
#
ssh myuser@myhost find $APACHE_HOME/cache/plsql/plsql -type d -name "[0-9]*" -exec rm -R {} \;
#
exit

You may need some type of quotes for that line.

Why not just install a cron job on each web server to clear the cache?

Hi Perderabo,

The web cache is cleared only on specific instances like when it is brought out of rotation or when we apply a patch to our database or a new build etc.

Since I do not have any control over these times, I cannot put this in cron.

RTM,
I will try your script and let you know.

Thanx

python should be able to do what you want.

it has the ability to logonto remote machines and execute the rest of teh script.

can someone give me a perl script to do that please??? or a php one?

Expect can also do that, on a more controlled level (expect filters input/output and manipulates it/enters it). I've had quite a large amount of sucess with expect.

also, assuming that you have wget on the remote pcs, you could simply write a script that will wget a blank file (called run) on a ftp or http server somewhere. then, when you want to run the script, you could copy the file to the http/ftp server, and wait for the script to run, then delete the file from the ftp server. a bit mc guyver-ed, but gets the job done just the same.

this forum is to help you on your way not do it for you.