1846028 Members
3263 Online
110253 Solutions
New Discussion

script wanted

 
haeman
Frequent Advisor

script wanted

I have two servers , sometimes they have problem to transfer files ( may be the connection problem ), so sometimes there are some files did not transferred to remote site ( one direction only , from server A to server B ) , so I would like to have a script to check if the files are sucessfully transferred , the condition of the checking is as below :


when found a new .err extension file in /tmp , then wait 5 minutes ( because assume the file transfer need 5 minutes ) , and then check the files in directory /ora in both server are the same or not ( only check the files that are created within 30 minutes because there is another script will copy the file to server B in every 30 minutes ) , if any file in server A have but server B do not , then notify me which file is not transferred , in simply , what I want to check is the files ( created within 30 minutes ) in both server are exist or not when the .err file found , if any transfer problem , then notify me , could provide the script ?

thx
3 REPLIES 3
Shrikant Lavhate
Esteemed Contributor

Re: script wanted

Hi,

Just a thought. I am not good at scripting. Trying to give a simple draft. Hope its matching your criteria.

1- Enter IF loop if .err exist
use ls /tmp | grep -i err

2- under IF loop
chk files exists or not on both servers
use -mtime with find.
If yes then
check chksum for both files
If match then all good
If not throw error mail using mailx.
Will it remain a personal, if I broadcast it here!
OFC_EDM
Respected Contributor

Re: script wanted

What are you using to transfer the files?

If using scp you can capture the return code
EXIT STATUS
0 Operation was successful.
1, 2 Operation resulted in an undetermined error within sshfilecopy.
3 Destination is not directory, but it should be.
4 Connection to host failed.
5 Connection lost.
6 File does not exist.
7 No permission to access file
8 Undetermined error from sshfilexfer.
9 File transfer protocol mismatch.


EXAMPLES

The following example shows how to copy files from your local system to a remote system:

prompt>scp localfile user@remotehost:/dest/

If used in a script after the command capture the error code:

typeset -i RC # Create integer variable
# put at beginning of script

RC=$? # Put immediately after command

Then check the error code:

if [ ${RC} -eq 0 ] ; then
echo "Operation succeeded"
else
echo "There's been an error" | mailx -s "Subject" mail.recipient@somewhere.ca
fi

RC=0 # Reset the variable if you're putting into a loop

I used echo statements to indicate where you'd put the commands you'd like to run after the copy based on the success/failure.

I didn't do a compare of the files after because if SCP has a return code of 0 then the file from the Source is definately on the Destination server.

Note this is KSH script syntax.

What tools do you have available to you to look at the directory contents on the remote server(s)? Can you SSH to/from each server?
The Devil is in the detail.
Ralph Grothe
Honored Contributor

Re: script wanted

Though, as Kevin suggested the evaluation of the SSH command's return code may suffice most of the times,
I have always implemented additionally in my scripts which involve any sort of transfer between hosts (usually by SSH) a postprocessing that compares the check sums or a hash digest taken of the files on the source system with those after successful transfer on the target system.
This is simply comparing two strings of the output from a command like cksum or md5sum for instance.
Most scripting languages also have custom modules with function or method calls for these calculations.

Madness, thy name is system administration