You are on page 1of 3

#| Hora (0-23),

#| | Dia do mes (1-31),


#| | | Mes do ano (1-12),
#| | | | Dia da semana (0-6 0-Domingo),
#| | | | | Comandos
#Minuto (0-59),
#| Hora (0-23),
#| | Dia do mes (1-31),
#| | | Mes do ano (1-12),
#| | | | Dia da semana (0-6 0-Domingo),
#| | | | | Comandos
echo "${1}" >> ${SFTPSCRIPT}_${SFTP_ID}.sh
}
# getting the info of the file
# parameters: 1 - origination folder, 2 - file mask, 3 - destination folder
GetFile(){
OrigDir=${1}
FileMask=${2}
DestDir=${3}
for currf in `/bin/ls -fgG ${OrigDir}/TX3/RAWDATA/ARCHIVE/${dir_date_mask}/${Fil
eMask}*|grep "${file_date_mask}"|awk '{print $NF}'`
do
# get just the original name of the file (without the additional infor a
fter the "#" and without the directory)
JustFile=`echo "${currf}"|awk -F# '{print $1}'|awk -F\/ '{print $NF}'`
# remove the "0" and "1" if exist at the end of the file name
DestFile=`echo "${DestDir}/${JustFile}"|sed 's/\.BCK0$/.BCK/'|sed 's/\.B
CK1$/.BCK/'`
if [ -e ${currf} ]
then
AddLineMiddle "${currf}" "${DestFile}"
Entering Ex mode. Type "visual" to go to Normal mode.
:x
"scripts/homo/transferfilesb.sh" 126L, 3121C written
[cvidya@arachicha ~]$ cat /home/cvidya/scripts/homo/transferfilesb.sh
#--------------------------------------------------------------
# Created by Ivaylo Shalev on 10 Jan 2014
# Copyrigth by cVidya
# Modified by
#--------------------------------------------------------------
#!/bin/sh
PROG_ID=$$
PROG=`basename ${0}`
# check if script is already/still running
#if [ `ps -fe|grep ${PROG}|grep -v ${PROG_ID}|grep -cv grep` -gt 0 ]
#then
# exit
#fi
SCRIPT=`echo ${PROG} | sed 's/\.sh$//'`
USERNAME=`id | sed 's/^uid=[0-9]*(//; s/).*//'`
file_date_mask=`date +' %b %e %H:' -d "4 hour ago"`
dir_date_mask=`date +'%Y%m%d' -d "4 hour ago"`
# folders list file structure
# Origination folder (relative path) | File Mask | Destination folder (absolute
path)
# /work/MSC/ERICSSON_GSM/ARACA | 0533 | /iris/ETL1/MSC/ERICSSON_GSM/A
RACA/TX3/RAWDATA/INPUT
DIRLIST=~/scripts/homo/folderslist.txt
LOGFILE=~/scripts/homo/${SCRIPT}.log
SFTPSCRIPT=~/scripts/homo/sftpupload
# functions
EchoMsg(){
echo "[`date +'%Y-%m-%d %T'`] ${1}" >> ${LOGFILE}
}
AddLineBegin(){
echo "#!/bin/sh" > ${SFTPSCRIPT}_${SFTP_ID}.sh
AddLine ""
AddLine "sftp iris@brtlvlts0085sl 2>>${LOGFILE} <<!"
}
AddLineMiddle(){
if [ $(( ${fcnt} % 1000 )) -eq 0 ] && [ ${fcnt} -gt 0 ]
then
# add footer to old
AddLineEnd
# add header to new
AddLineBegin
fi
# add file
AddLine "put -P ${1} ${2}.cvidya"
#AddLine "chmod 777 ${2}.cvidya"
AddLine "rename ${2}.cvidya ${2}"
}
AddLineEnd(){
AddLine "bye"
AddLine "!"
AddLine ""
AddLine "echo \"[\`date +'%Y-%m-%d %T'\`] \`basename \${0}\` finished.\" >>${LOG
FILE}"
# execute script
chmod 777 ${SFTPSCRIPT}_${SFTP_ID}.sh
${SFTPSCRIPT}_${SFTP_ID}.sh &
SFTP_ID=${SFTP_ID}+1
}
AddLine(){
echo "${1}" >> ${SFTPSCRIPT}_${SFTP_ID}.sh
}
# getting the info of the file
# parameters: 1 - origination folder, 2 - file mask, 3 - destination folder
GetFile(){
OrigDir=${1}
FileMask=${2}
DestDir=${3}
for currf in `/bin/ls -fgG ${OrigDir}/TX3/RAWDATA/ARCHIVE/${dir_date_mask}/${Fil
eMask}*|grep "${file_date_mask}"|awk '{print $NF}'`
do
# get just the original name of the file (without the additional infor a
fter the "#" and without the directory)
JustFile=`echo "${currf}"|awk -F# '{print $1}'|awk -F\/ '{print $NF}'`
# remove the "0" and "1" if exist at the end of the file name
DestFile=`echo "${DestDir}/${JustFile}"|sed 's/\.BCK0$/.BCK/'|sed 's/\.B
CK1$/.BCK/'`
# add first sftp script header
AddLineBegin
t#while read ff
for ff in $(<${DIRLIST})
do
Param1=`echo "${ff}"|awk -F\| '{print $1}'`
Param2=`echo "${ff}"|awk -F\| '{print $2}'`
Param3=`echo "${ff}"|awk -F\| '{print $3}'`
ch=`ls ${Param1}/TX3/RAWDATA/ARCHIVE/${dir_date_mask}/${Param2}* 2>&1|he
ad -1`
if [ `echo "${ch}"|grep -c "ls: "` -eq 0 ]
then
GetFile "${Param1}" "${Param2}" "${Param3}"
fi
done
#done < ${DIRLIST}
# add last sftp script footer
AddLineEnd
# script body end
EchoMsg "Finished. ${fcnt} files processed."

You might also like