I have two source files created in unix folder say file1.dat and file2.dat.
I need to send the files to mainframe using SCP.
The unix script I wrote is as below:
if [[ -f $MY_DIR/$SOURCE1 ] -a [ -f $MY_DIR/$SOURCE2 ]]; then
scp -P 2222 $MY_DIR/$SOURCE1 $MFDESTINATION1
if [ $? -ne 0 ]; then
ftp_status='100'
$LOG_DIR/my_log $0 "(SCP FOR $SOURCE1) ended in ERROR"
exit 255
else
scp -P 2222 $MY_DIR/$SOURCE2 $MFDESTINATION2
if [ $? -ne 0 ]; then
ftp_status='100'
$LOG_DIR/my_log $0 "(SCP FOR $SOURCE2) ended in ERROR"
exit 255
fi
fi
fi
The logic works fine for file1 i.e. if file1 transfer results in error, do not transfer file2.
But if file1 transfer succeeds, file2 transfer gets initiated. If that fails, file1 is already in MF.
I dont want that. I want to send either both the files or none of them.
How to achieve that ?
I know last option is to delete file1 in MF if file2 transfer fails. But is there any other way ?
Thanks for reading!
What I would do is transfer the files to a temporary location on the same filesystem where the final files should be (or with a temporary name that won’t be picked up by the remote service), and rename the files if both transfers were successful. The rename should never fail on the same filesystem if you make sure the filenames are available.
cheers,
mitch