Erreur scrpit shell : fin de fichier prématuré.
Résolu
Lacapricorne
Messages postés
17
Statut
Membre
-
Lacapricorne Messages postés 17 Statut Membre -
Lacapricorne Messages postés 17 Statut Membre -
Bonjour,
Je suis assez débutante en script shell.
J'ai un script shell qui, d'abord exporte les données de la base de données mysql vers fichier.csv puis comprèsse ce fichier et enfin l'envoi vers un autre serveur dont l'adresse IP est 192.168.56.103.
Voici mon code :
Mais voilà, quand j’exécute mon script il retourne toujours l'erreur : " ligne44: Erreur de syntaxe : fin de fichier prématurée"
J'essai de trouver ou se trouve exactement l'erreur mais je n'y arrive pas. Est ce que quelqu'un peut m'aider s'il vous plait, je sais plus du tout quoi faire.Merci beaucoup.
Je suis assez débutante en script shell.
J'ai un script shell qui, d'abord exporte les données de la base de données mysql vers fichier.csv puis comprèsse ce fichier et enfin l'envoi vers un autre serveur dont l'adresse IP est 192.168.56.103.
Voici mon code :
#!/bin/sh
currentTimeStartExp=`date +'20%y-%m-%d %H:%M:%S'`
#currentfile="/data/barring/cdr_rated_$1"+".csv"
#currentfile="/data/tmp/cdr_rated_$1.csv"
#currentfile="/DWH2017/SAVE/Reste/cdr_rated_$1"+".csv"
if [ $# -eq 0 ]
then
currentfile="/archives/export_base/export_"`date +'20%y-%m-%d' -d '-1 day'`".csv"
currentdate=`date +'20%y-%m-%d' -d '-1 day'`
else
currentfile="/archives/export_base/export_$1.csv"
currentdate=$1
fi
echo "Start EXPORT $currentfile at $currentTimeStartExp"
#Declaring mysql BIG5 DB connection
DBIG_MASTER_DB_USER='root'
DBIG_MASTER_DB_PASSWD=''
DBIG_MASTER_DB_PORT=3306
DBIG_MASTER_DB_HOST='192.168.56.102'
DBIG_MASTER_DB_NAME='bdorange'
#mysql command to connect to database prod
/usr/bin/mysql -u$DBIG_MASTER_DB_USER -p$DBIG_MASTER_DB_PASSWD -P$DBIG_MASTER_DB_PORT -h$DBIG_MASTER_DB_HOST -D$DBIG_MASTER_DB_NAME <<EOF
select * from $DBIG_MASTER_DB_NAME.affecter where iddate between '$currentdate' and '$currentdate 23:59:59' into outfile '$currentfile' fields terminated by '|';
EOF
#currentTimeEndExp=`date +'20%y-%m-%d %H:%M:%S'`
if [ -f "$currentfile" ]
then
currentfilegz="$currentfile.gz"
gzip $currentfile
if [ -f "$currentfilegz" ]
then
sshpass -p "rasoamanarivo" ssh root@192.168.56.102<<EOF
sshpass -p "rasoamanarivo" scp -p -r root@192.168.56.103:$currentfilegz /DWHFB/archivecsvprod
EOF
echo "FTP :$currentfilegz OK ."
currentTimeEndExp=`date +'20%y-%m-%d %H:%M:%S'`
echo "End EXPORT $currentfilegz at $currentTimeEndExp"
rm -rf $currentfilegz
fi
fi
Mais voilà, quand j’exécute mon script il retourne toujours l'erreur : " ligne44: Erreur de syntaxe : fin de fichier prématurée"
J'essai de trouver ou se trouve exactement l'erreur mais je n'y arrive pas. Est ce que quelqu'un peut m'aider s'il vous plait, je sais plus du tout quoi faire.Merci beaucoup.
A voir également:
- Erreur de syntaxe : fin de fichier prématurée
- Fichier bin - Guide
- Fichier epub - Guide
- Fichier rar - Guide
- Comment réduire la taille d'un fichier - Guide
- Fichier .dat - Guide
[root@localhost reprocess]# cat -A Export2.sh #!/bin/sh^M$ currentTimeStartExp=`date +'20%y-%m-%d %H:%M:%S'`^M$ ^M$ if [ $# -eq 0 ]^M$ then^M$ currentfile="/archives/export_base/export_"`date +'20%y-%m-%d' -d '-1 day'`".csv"^M$ currentdate=`date +'20%y-%m-%d' -d '-1 day'`^M$ else^M$ currentfile="/archives/export_base/export_$1.csv"^M$ currentdate=$1^M$ fi^M$ echo "Start EXPORT $currentfile at $currentTimeStartExp"^M$ #Declaring mysql BIG5 DB connection ^M$ DBIG_MASTER_DB_USER='root'^M$ DBIG_MASTER_DB_PASSWD=''^M$ DBIG_MASTER_DB_PORT=3306^M$ DBIG_MASTER_DB_HOST='192.168.56.102'^M$ DBIG_MASTER_DB_NAME='bdorange'^M$ ^M$ #mysql command to connect to database prod^M$ /usr/bin/mysql -u$DBIG_MASTER_DB_USER -p$DBIG_MASTER_DB_PASSWD -P$DBIG_MASTER_DB_PORT -h$DBIG_MASTER_DB_HOST -D$DBIG_MASTER_DB_NAME <<EOF^M$ select * from $DBIG_MASTER_DB_NAME.affecter where iddate between '$currentdate' and '$currentdate 23:59:59' into outfile '$currentfile' fields terminated by '|';^M$ EOF^M$ ^M$ if [ -f "$currentfile" ]^M$ then^M$ ^Icurrentfilegz="$currentfile.gz"^M$ ^Igzip $currentfile^M$ ^Iif [ -f "$currentfilegz" ]^M$ ^Ithen^M$ ^M$ ^I^Isshpass -p "rasoamanarivo" ssh osadmin@192.168.56.102.<<EOF^M$ ^Isshpass -p "rasoamanarivo" scp -p -r root@192.168.56.103:$currentfilegz /DWHFB/archivecsvprod^M$ EOF^M$ ^Iecho "FTP :$currentfilegz OK ."^M$ ^I^IcurrentTimeEndExp=`date +'20%y-%m-%d %H:%M:%S'`^M$ ^I^Iecho "End EXPORT $currentfilegz"^M$ ^I^Irm -rf $currentfilegz^M$ ^Ifi^M$ ^M$ fi^M$ [root@localhost reprocess]#Toutes les fins de lignes sont au format Micro$oft (^M$) ;-((