Ciao a tutti,
Just voluto un po 'di ingresso su uno script sto utilizzando per importare file in un database MySQL.
Il processo è abbastanza semplice: il mio server principale delle esportazioni di questi file e FTPS loro. Ho uno script che FTPS al funzionamento della macchina che esegue questo script. FTP script viene eseguito senza problema ogni volta, bith dal cron o manualmente.
Il problema si verifica quando il cron esegue lo script qui di seguito. Si prega di essere gentili, questi sono il mio primo script.
Il ciclo viene eseguita correttamente, la prima volta, ma quando si torna nuovamente loop muore nel punto in cui è chiamato nuovamente mysqlimport. Il primo file, in questo caso il website_tabProperty.txt funziona bene. Si muore a website_tabBuilding.txt.
Il mio cron è impostato per eseguire lo script come root.
Sono stato in esecuzione manualmente questo script ". /" Per un lungo periodo di lavori e ogni volta.
Ho un problema la sua figura con il loop e la sopraelevazione di cron, ma ho elaborato nulla.
Grazie per il vostro aiuto.
Conto
Codice:
#!/bin/bash
echo "Starting new batch import `date`"
echo "Starting new batch import `date`" >> /root/import.log
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Imporatnt: The last file and table in these arrays MUST be the data that is targeted for
#the append operation.
#define the files names for import and existance verification. These are renamed to the names below
file_name[1]=/root/website_tabProperty.txt
file_name[2]=/root/website_tabBuilding.txt
file_name[3]=/root/website_tabApartment.txt
file_name[4]=/root/website_tabMeters.txt
file_name[5]=/root/website_tabReadings.txt
#define the file names for importation. The file names must match the table names
target_file_name[1]=/root/tabProperty.txt
target_file_name[2]=/root/tabBuilding.txt
target_file_name[3]=/root/tabApartment.txt
target_file_name[4]=/root/tabMeters.txt
target_file_name[5]=/root/tabReadings.txt
#define the target tables to flush
target_table[1]=tabProperty
target_table[2]=tabBuilding
target_table[3]=tabApartment
target_table[4]=tabMeters
target_table[5]=tabReadings
#this number nust be one higher than the max index in the arrays.
MAX_LOOP=6
#Set this value to the index we want to append - will force it to skip the flush
APPEND_INDEX=5
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#set the file name suffix for the renaming routine
suffix=`date +%m_%d_%Y`
COUNTER=1
while [ $COUNTER -lt $MAX_LOOP ]; do
echo "---------------------------------------"
echo "---------------------------------------" >> /root/import.log
echo "Processing index - "$COUNTER
echo "Processing index - "$COUNTER >> /root/import.log
DIR=${file_name[COUNTER]}
if [ -f $DIR ];then
echo "Original "${file_name[COUNTER]}" exists"
echo "Original "${file_name[COUNTER]}" exists" >> /root/import.log
echo "Renaming "${file_name[COUNTER]}
echo "Renaming "${file_name[COUNTER]} >> /root/import.log
cp ${file_name[COUNTER]} ${target_file_name[COUNTER]}
echo "Removing "${file_name[COUNTER]}
echo "Removing "${file_name[COUNTER]} >> /root/import.log
rm ${file_name[COUNTER]}
#Only flush the table if it is not the last one in the index
if [ $COUNTER != $APPEND_INDEX ]; then
echo "Flushing "${target_table[COUNTER]}
echo "Flushing "${target_table[COUNTER]} >> /root/import.log
mysql -u root -p8895asdf7665553 -e "use wellspring; delete from "${target_table[COUNTER]}";"
sleep 2
else
echo "Not Flushing "${target_table[COUNTER]}
echo "Not Flushing "${target_table[COUNTER]} >> /root/import.log
fi
echo "Importing "${target_file_name[COUNTER]}
echo "Importing "${target_file_name[COUNTER]} >> /root/import.log
mysqlimport -u root -p8895asdf7665553 --local wellspring ${target_file_name[COUNTER]}
sleep 2
echo "Renaming "${target_file_name[COUNTER]}
echo "Renaming "${target_file_name[COUNTER]} >> /root/import.log
cp ${target_file_name[COUNTER]} ${target_file_name[COUNTER]}.$suffix
sleep 1
echo "Removing "${target_file_name[COUNTER]}
echo "Removing "${target_file_name[COUNTER]} >> /root/import.log
rm ${target_file_name[COUNTER]}
sleep 1
else
echo "Original "${file_name[COUNTER]}" does not exist"
echo "Original "${file_name[COUNTER]}" does not exist" >> /root/import.log
fi
let COUNTER=COUNTER+1
done
echo "---------------------------------------"
echo "---------------------------------------" >> /root/import.log
echo "Finished batch import `date`"
echo "Finished batch import `date`" >> /root/import.log
echo "*********************************************************************************"
echo "*********************************************************************************" >> /root/import.log
exit