For loop scp transfers check if all iterations successful


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For loop scp transfers check if all iterations successful
# 1  
Old 04-14-2010
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:

Code:
for file in $ORIGLOC/*
do            
[[ -d $file ]] && continue # skip subdirectories             
  myfile=`basename ${file%\.*}` #remove .txt and base path
  monthbefore=`date -d 'month ago' "+%Y%m"` #previous month date
  mv $file $ARCHLOC/${myfile}_$monthbefore.txt >> $LOGFILE
  touch $ARCHLOC/${myfile}_$monthbefore.ready

scp $ARCHLOC/${myfile}_$monthbefore DESTUSER@$DESTSERV:$DESTLOC >> $LOGFILE
     if [ $? -eq "0" ]; then
           echo $file Transferred Successfully at `date` >> $LOGFILE
           scp $ARCHLOC/${myfile}_$monthbefore.ready $DESTUSER@$DESTSERV:$DESTLOC >> $LOGFILE
           else
           echo $file Transfer failed at `date` >> $LOGFILE
fi

# 2  
Old 04-14-2010
I don't see the "done" line in your script, but if you start a new $LOGFILE with each run, you could add
Code:
mailx -s "SCP Results" john.doe <$LOGFILE
cat $LOGFILE >>BIGLOGFILE

after the done statement
# 3  
Old 04-15-2010
Quote:
Originally Posted by jgt
I don't see the "done" line in your script, but if you start a new $LOGFILE with each run, you could add
Code:
mailx -s "SCP Results" john.doe <$LOGFILE
cat $LOGFILE >>BIGLOGFILE

after the done statement
Yeah these people are picky and would only want to be emailed IF any of the iterations failed. I don't want to email the log on each iteration though.

I think i am going to make a variable in the else statement. like set FAILED=0
if command not successful increment failed and then email if failed does not equal 0
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Store 'for' loop iterations in memory

hi all, I'm writting a simple bash script to do a recursive paste over >10000 files with two columns each. The files looks like this: A1BG 3 A1CF 3 A2M 3 A4GALT 5 AAAS 2 AACS 2 AADAT 2 AAGAB 4 AAK1 3 AAMP 2 AANAT 3 AARS 2 AARS2 3 AARSD1 ... (1 Reply)
Discussion started by: lsantome
1 Replies

2. Shell Programming and Scripting

Scp/Rsync transfers stopped working?

Hi all, I have a backup script from my work computer to my home computer for my research for multiple reasons. It's a simple rsync script, with about 5 gigs of data. (Obviously with rsync it doesn't transfer 5 GB every time.). Recently, it has stopped working, scp also doesn't work, it simply... (1 Reply)
Discussion started by: corrado33
1 Replies

3. Shell Programming and Scripting

How to check whether the sftp script is successful??

hi, how can i check whether the sftp connectivity is successful or not?? i am using expect script to connect to sftp.. sftp_script spawn /usr/bin/sftp abc@ftp.xyz.com expect "abc@ftp.xyz.com's password:" send "password\r" expect "sftp>" send "mput *.txt\r" expect "sftp>" send "bye\r"... (8 Replies)
Discussion started by: Little
8 Replies

4. 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

5. Homework & Coursework Questions

Script to check transfer was successful

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a script that performs a post processing action: The run time environment of the script has the... (2 Replies)
Discussion started by: kenrowe
2 Replies

6. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: derndingle
1 Replies

7. Cybersecurity

automatic SCP transfers issues

Hi, I'm trying to set up scp but it isn't as nice as WinSCP. My requirement is to transfer a file from one machine to another with scp. This would run in a .ksh so it would need to avoid prompts (password/are you sure). First I tried this with v2: SSH with Keys HOWTO: SSH with Keys in a console... (1 Reply)
Discussion started by: Dird
1 Replies

8. UNIX for Dummies Questions & Answers

probloem in scp command 99% content only transfers

hi every one.. i am new to working in unix environment.. i have a problem in transferring files using scp command.. i am transferring files using scp command on one unix manchine to another unix machine.. the syntax is scp -r sourcedirectory destination directory The files in sourcedirectory... (1 Reply)
Discussion started by: GovindGembali
1 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

For Loop iterations

I have a silly beginners question here: I'm running a for loop within an awk command as follows, however the loop only runs once, instead of 2 through to 11 and then terminating. As the output to screen of x (line 6) shows x to equal 12, when it should be 1. --------------------------- awk... (2 Replies)
Discussion started by: sirtrancealot
2 Replies
Login or Register to Ask a Question