Operating System - HP-UX
1752778 Members
6145 Online
108789 Solutions
New Discussion юеВ

Re: Script for scp to send a file to secondary server when a primary server fails

 
SubhadraRaju
New Member

Script for scp to send a file to secondary server when a primary server fails

I have two servers where one is primary and one is secondary. I Will generally move my files to primary server with secondary server as backup. If suddenly my primary server fails or is down, then the secondary server will be in use. I need to write the script for this. As I am new on unix machine couldnt find a solution. Please let me know if any further information required.


Thanks in Advance..


6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: Script for scp to send a file to secondary server when a primary server fails

I assume this should be a simple matter of changing the server name in your scp command. You can put the name it a file and change it manually:
scp ... $(< server-file):

You could also do this automatically if a dummy scp times out, switch to the secondary server.
SubhadraRaju
New Member

Re: Script for scp to send a file to secondary server when a primary server fails

Thanks for the info Dennis. But found the solution myself.

In the script i have written the below lines(sample), it worked.

user_dir=local_path
remoteserver=ipaddress1
$ping $remoteserver
if [ $? -eq 0 ]
remote_dir=remotepath1
else
remoteserver=ipaddress2
remote_dir=remotepath2


In the remaining script, the filename is read and moved to the remote directory.

If the secondary server also fails then no one can help. Need to setup both servers if there is any problem.
Dennis Handly
Acclaimed Contributor

Re: Script for scp to send a file to secondary server when a primary server fails

> $ping $remoteserver

You'll need to add: -n 1 -m 1
Be aware the server can be "down"/hung and still respond to pings. Using scp with a timeout would be a more robust solution.
SubhadraRaju
New Member

Re: Script for scp to send a file to secondary server when a primary server fails

Yes Dennis, I forgot to mention earlier. I have given it like

$ping -c 2 $remoteserver

so for a count of 2 pings I am confirming that the server is up, if not then a secondary server is used. Can you please tell me what is the difference between the command you applied and the command i mentioned here.
Steven Schweda
Honored Contributor

Re: Script for scp to send a file to secondary server when a primary server fails

> so for a count of 2 pings I am confirming
> that the server is up [...]

You're confirming that it responds to "ping",
not that it does "scp" correctly. Which is
more important to you? Is the best test of
whether you can transfer a file using "scp"
to run "ping", or to try to transfer a file
using "scp"?

> Using scp with a timeout would be a more
> robust solution.

And/or look at the exit status returned by
"scp".
Dennis Handly
Acclaimed Contributor

Re: Script for scp to send a file to secondary server when a primary server fails

>what is the difference between the command you applied and the command I mentioned here.

I see no -c option to HP-UX ping(1m) on 11.31.
-n is the count and -m is the timeout in seconds.