Précédent   Forum des professionnels en informatique > Systèmes > Linux > Applications > Shell
Shell Vos questions sur l'utilisation des commandes shell
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 07/07/2008, 17h30   #1
Futur Membre du Club
 
Inscription : juin 2008
Messages : 95
Détails du profil
Informations personnelles :
Âge : 24

Informations forums :
Inscription : juin 2008
Messages : 95
Points : 16
Points : 16
Par défaut Mot de passe Mysql

Bonjour!!
sur mon ancien pc (Suse 9.2) j'ai fait un script pour récupérer un fichier txt d'un programme de gestion et l'envoyé dans ma base de donnée mysql depuis j'ai changé de pc maintenant j'ai une suse 10.3 mais ma base de donnée est protégé par un mot de passe et maintenant je n'arrive plus a lancé mon script voilà mes code avant et aprés:
avant:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
 
. ./generals.inc
 
rm -f log.txt
 
if [ ! -x $EXPORT_BIN ] ; then
	log "$EXPORT_BIN n'est pas executable" ERROR
	exit 1
fi
 
clear
log "**** Exportation Ciel -> db FBI ****\n"
log   "====================================\n\n"
sleep
log "Backup de la table $DB_FBI.t_articles\n"
sleep
# Cr�er le r�pertoire de backup s'il n'existe pas encore
[ ! -d $BACKUP_DIR ] && mkdir $BACKUP_DIR
# G�n�re le nom pour le backup de la table
f="$BACKUP_DIR/t_articles_`date +"%d-%m-%Y_%H:%M:%S"`.sql"
# Utilise mysqldump pour backuper le contenu de la table t_articles
mysqldump --add-drop-table $DB_FBI t_articles -u $DB_USER -h $DB_HOST $DB_PASS > $f 2>&1 | tee -a log.txt
[ $? -ne 0 ] || [ "`grep 'mysqldump:' $f`" != "" ] && log "mysqldump n'a pas r�ussi � sauvegarder la table\n" ERROR
bzip2 $f
log "$DB_FBI.t_articles export� dans $f.bz2\n"
# Choix du fichier d'export
read -n100 -p "Fichier d'export issu de Ciel [$EXPORT_FILE]: " export_file
[ "$export_file" == "" ] && export_file=$EXPORT_FILE
if [ ! -r "$export_file" ] ; then
	log "Le fichier n'est pas accessible (existe?)\n" ERROR
fi
# Retire les \r issus de windows
log "Formate le fichier � importer\n\n"
cat $export_file | sed 's/\r//g' > _tmp.txt
# Exporte
log "---- Lance $EXPORT_BIN ----\n\n"
$EXPORT_BIN _tmp.txt "$DB_HOST" "$DB_FBI" "$DB_USER" "$EXE_DB_PASS" 2>&1 | tee -a log.txt
rm -f _tmp.txt
 
log "Notifie la mise � jour dans la db\n"
fname=$(basename "$export_file")
echo "INSERT INTO t_maj VALUES(0,now(),'Maj t_articles via export Ciel ($fname)')" | mysql $DB_FBI -u $DB_USER -h $DB_HOST $DB_PASS
log "FIN\n\n"
exit 0
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
BACKUP_DIR="../_backup_"
 
EXPORT_FILE="export_ciel.txt"
 
EXPORT_BIN="../../dev/sources/export_ciel"
DUMP_BIN="`which mysqldump` --add-drop-table"
 
MAILS_DIR="/srv/www/htdocs/mails"
MAIL_SUBJECT="Promotion FBI Distribution"
MAIL_SENDER="mails@fbi-distribution.com"
SVR_ADDR="smtp.wanadoo.fr"
SVR_PORT="25"
 
SSH_USER="root"
SVR_WWW_DIR="/home/httpd/vhosts/fbi-distribution.com/httpdocs"
LCL_WWW_DIR="/srv/www/htdocs"
 
DB_HOST="127.0.0.1"
DB_FBI="fbi"
DB_MAIL="mails"
DB_USER="root"
DB_PASS=""
#DB_PASS="-p ***password***"
EXE_DB_PASS=""
#EXE_DB_PASS="***password***"
 
function log()
{
        if [ "$2" == "ERROR" ] ; then
                echo -ne "ERROR: $1"
                echo -ne `date +"%d/%m/%Y %H:%M:%S"`":\tERROR:\t$1" >> log.txt
                exit 1
        else
                echo -ne "$1"
                echo -ne `date +"%d/%m/%Y %H:%M:%S"`":\t$1" >> log.txt
        fi
}
 
function sleep()
{
#       usleep 500000
        usleep 5
}
maintenant
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
 
. ./generals.inc
 
rm -f log.txt
 
if [ ! -x $EXPORT_BIN ] ; then
	log "$EXPORT_BIN n'est pas executable" ERROR
	exit 1
fi
 
clear
log "**** Exportation Ciel -> db FBI ****\n"
log   "====================================\n\n"
sleep
log "Backup de la table $DB_FBI.t_articles\n"
sleep
# Cr�er le r�pertoire de backup s'il n'existe pas encore
[ ! -d $BACKUP_DIR ] && mkdir $BACKUP_DIR
# G�n�re le nom pour le backup de la table
f="$BACKUP_DIR/t_articles_`date +"%d-%m-%Y_%H:%M:%S"`.sql"
# Utilise mysqldump pour backuper le contenu de la table t_articles
mysqldump --password=jeromevalid --add-drop-table $DB_FBI t_articles -u $DB_USER -h $DB_HOST -p $DB_PASS > $f 2>&1 | tee -a log.txt
[ $? -ne 0 ] || [ "`grep 'mysqldump:' $f`" != "" ] && log "mysqldump n'a pas réussi à sauvegarder la table\n" ERROR
bzip2 $f
log "$DB_FBI.t_articles exporté dans $f.bz2\n"
# Choix du fichier d'export
read -n100 -p "Fichier d'export issu de Ciel [$EXPORT_FILE]: " export_file
[ "$export_file" == "" ] && export_file=$EXPORT_FILE
if [ ! -r "$export_file" ] ; then
	log "Le fichier n'est pas accessible (existe?)\n" ERROR
fi
# Retire les \r issus de windows
log "Formate le fichier à importer\n\n"
cat $export_file | sed 's/\r//g' > _tmp.txt
# Exporte
log "---- Lance $EXPORT_BIN ----\n\n"
$EXPORT_BIN _tmp.txt "$DB_HOST" "$DB_FBI" "$DB_USER" "$DB_PASS" "$EXE_DB_PASS" 2>&1 | tee -a log.txt
rm -f _tmp.txt
 
log "Notifie la mise à jour dans la db\n"
fname=$(basename "$export_file")
echo "INSERT INTO t_maj VALUES(0,now(),'Maj t_articles via export Ciel ($fname)')" | mysql $DB_FBI -u $DB_USER -h $DB_HOST -p $DB_PASS
log "FIN\n\n"
exit 0
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
BACKUP_DIR="../_backup_"
 
EXPORT_FILE="export_ciel.txt"
 
EXPORT_BIN="../utils/dev/sources/export_ciel"
DUMP_BIN="`which mysqldump`--password=jeromevalid --add-drop-table"
 
MAILS_DIR="/srv/www/site/htdocs/mails"
MAIL_SUBJECT="Promotion FBI Distribution"
MAIL_SENDER="mails@fbi-distribution.com"
SVR_ADDR="smtp.orange.fr"
SVR_PORT="25"
 
SSH_USER="root"
SVR_WWW_DIR="/home/httpd/vhosts/fbi-distribution.com/httpdocs"
LCL_WWW_DIR="/srv/www/site/htdocs"
 
DB_HOST="127.0.0.1"
DB_FBI="fbi"
DB_MAIL="mails"
DB_USER="root"
DB_PASS="-p jeromevalid"
#DB_PASS="-p ***password***"
EXE_DB_PASS=""
#EXE_DB_PASS="***password***"
 
function log()
{
        if [ "$2" == "ERROR" ] ; then
                echo -ne "ERROR: $1"
                echo -ne `date +"%d/%m/%Y %H:%M:%S"`":\tERROR:\t$1" >> log.txt
                exit 1
        else
                echo -ne "$1"
                echo -ne `date +"%d/%m/%Y %H:%M:%S"`":\t$1" >> log.txt
        fi
}
 
function sleep()
{
#       usleep 500000
        usleep 5
}
quelqu'un a une idée?? merci
philippe57460 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h04.


 
 
 
 
Partenaires

Hébergement Web