rm files after testing for successful scp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rm files after testing for successful scp
# 1  
Old 11-14-2012
rm files after testing for successful scp

First off, I know this is sort of a rehash of similar questions that have been asked in other closed threads, but I haven't been able to figure out how to apply the answers provided in those threads to my scenario and make it work.

I am working on a script in KSH on AIX 5.1 that will do a bulk unload of a DB2 table to a directory on the AIX server, then it should gzip the file and SCP it to a directory on a RHEL server and then remove the file from the AIX server (since space is very limited on the AIX server and some of these bulk unloads will be very large.)

Code:
scp2 /${extdir}/${tablename}.del.gz ${lzuser}@${lzserver}:/${lzdir}/ >> $logdir/$logfile 2>> $logdir/$logfile
 if [[ $? -ne 0 ]]
    then
    echo "SCP to Landing Zone failed, exiting script" >> $logdir/$logfile
    exit 100
    else
    echo "SCP to EPMA Landing Zone Successful, go ahead and remove the files." >> $logdir/$logfile
    rm /${extdir}/${tablename}.del.gz >> $logdir/$logfile 2>> $logdir/$logfile
    rm /${extdir}/${tablename}/*.load >> $logdir/$logfile 2>> $logdir/$logfile
fi

The problem I'm running into is that even if the SCP fails (I can force it to fail by specifying an invalid server name as the lzserver) the files are still being removed.

In the other threads on the topic, it showed putting the logic for testing the return code from SCP into a loop, but I don't understand how exactly to make that work. Also, I wasn't clear if the loop was something that would apply to my scenario or if it was particular to the other thread where it was dealing with finding log files and moving them.

Thanks in advance for the help!
# 2  
Old 11-14-2012
After scp you can check if the file was successfully copied by doing:-
Code:
FNAME=$( ssh ${lzuser}@${lzserver} "ls /${lzdir}/${tablename}.del.gz" )
if [ "${FNAME}" = "${tablename}.del.gz" ]
then
      # Copy successful
else
      # Copy failed
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. Shell Programming and Scripting

scp files

Need assistance I have ssh keys exchanged between servers for user ZID ssh works without password between ZID . "ssh SERVER A to SERVER B works" I have a property file on SERVER A which is owned by root and I need to transfer the file changing into ZID user and transfer to SERVER B ... (7 Replies)
Discussion started by: ajayram_arya
7 Replies

3. Shell Programming and Scripting

How to check if the merge of two files is successful?

Hi All, I have a requirement to check if the merge of files is successful or not. The script to merge files goes like this, cat Rewards_Header Rewards_Siebel_Notif_temp Rewards_Siebel_Remind105_temp > Rewards_Siebel Sometimes, the file Rewards_Siebel misses records from file... (5 Replies)
Discussion started by: anandek
5 Replies

4. UNIX for Dummies Questions & Answers

scp multiple files

Hi, I'm new to Linux. I would like to know how to scp a group of files. I have the below command, but it asks for remote password while sending each file. Is there a way to send all files (identified by - $ ls | grep '.*hrs0314a.*' | xargs -I {} grep -l '.*35663.*' {}) in one go? $ ls |... (6 Replies)
Discussion started by: don_tom
6 Replies

5. Shell Programming and Scripting

For loop scp transfers check if all iterations successful

All, I am using a for loop to SCP a bunch of files in a directory. I am having it then drop a .ready file name. Is there a way to check for the success of all iterations and then email upon fail or success? Example of part of my script: for file in $ORIGLOC/* do ] &&... (2 Replies)
Discussion started by: markdjones82
2 Replies

6. Solaris

Testing targets of link files > ln -s

Hi all Ive been given the task to write a script that tests that certain link files work, i.e. the physical directory the link points too, is actually there. Now, before I go down the route of ls -l | awk ...... or using test or find, is there a far more simpler command that I can use ? ... (2 Replies)
Discussion started by: sbk1972
2 Replies

7. Shell Programming and Scripting

SCP multiple files

Hi , I am doing SCP for copying log files from different server(around 24 server) I need to copy these bulk logfiles every 15 min. How can i do multiple SCP at the same time? My current code is like this scp $CUSTCARE_USER@$CUSTCARE_SERVER:$CUSTCARE_HOME/$CUSTCARE_LOG.*... (2 Replies)
Discussion started by: scorpio
2 Replies

8. UNIX for Dummies Questions & Answers

testing if files exist

I am trying to test arguments to see if they are files in any directory. I have : but it's not working (7 Replies)
Discussion started by: skooly5
7 Replies

9. UNIX for Advanced & Expert Users

SCP / SFTP successful but locks out target account

Hi, We have an interesting problem with F-Secure SSH (v 3.1.0) running on HP-UX. It seems that when scp or sftp commands are issued they are successful but it counts as a 'strike' against the target user locking the account out after 3 attempts. When the user is re-enabled in SAM - it reports... (4 Replies)
Discussion started by: b0bbins
4 Replies

10. Shell Programming and Scripting

testing for presence of files in ftp

I have a shell script which GETS a file, but I only want to run this script if $FILE exists on the remote host, don't know correct syntax.....please help ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD bin get $FILE rename export.prn export.prn.$TIMESTAMP !cat... (0 Replies)
Discussion started by: walterja
0 Replies
Login or Register to Ask a Question