Archiving files using shell script

Hi,

Thanks for that. I am now able to archive the files in the remote server using the below commands in the script. Pasting the section from the script

Remote2Local() {

	cd ${FILES_PATH} 2>/dev/null
	if [[ ${?} -gt 0 ]];then
          print -u2 "LocalSource path not found";
          rm ${LCK_FILE}
          exit 1;
        fi

	echo cd ${FILE_SOURCE_PATH} > ${TMP_SFTP_SCRPT}
	echo mget ${FILE_MASK} >> ${TMP_SFTP_SCRPT}
	
        # echo rm ${FILE_MASK} >> ${TMP_SFTP_SCRPT} Commented this line as part of the changes
		
	echo bye >> ${TMP_SFTP_SCRPT}
	sftp -oPort=${FILE_SOURCE_PORT} -b ${TMP_SFTP_SCRPT} ${FILE_SOURCE_ACCOUNT} 2>/dev/null 1>&2 
        rm ${TMP_SFTP_SCRPT}
	
	# Changes added to archive the files to �rchive' folder in the source path
	echo cd ${FILE_SOURCE_PATH}/archive > ${TMP_SFTP_SCRPT}
	echo mput ${FILE_MASK} >> ${TMP_SFTP_SCRPT}  
	echo bye >> ${TMP_SFTP_SCRPT}		
	sftp -oPort=${FILE_SOURCE_PORT} -b ${TMP_SFTP_SCRPT} ${FILE_SOURCE_ACCOUNT} 2>/dev/null 1>&2 
	rm ${TMP_SFTP_SCRPT}
	# End of change
}

In the code when I comment the 2>/dev/null 1>&2, I am able to see the attached information in the server. I would like to have similar information saved to a log file in remote server. Could you please help me with that?

Where is your log file defined? If it is an overall log for the script, then append the output to the existing log, perhaps like this:-

some_command >>/path/to/my_log.txt 2>&1

The double redirect >> appends to the file rather than overwrites it.

If you remove all the redirects to /dev/null you can also capture all the output from running the script to a file, if that's easier:-

/path/to/my_script parameter1 parameter2 parameter3 >/path/to/my_log.txt 2>&1

Do either of these achieve what you need?

Robin