Rapports in a log file with a script shell (linux batch) and redirection
Please help!!! ;)
I have a problem with this code in a batch file (Linux):Mil=`date +"%Y%m%d%H%M%S"`
batch=`echo "${DatMusic}"`
TabimportEnteteMusic="importentetemusic.dat"
{
grep '^ENTETE' ${IMPORT}/${DatMusic} > ${IMPORT}/$TabimportEnteteMusic
mysql -u basemine --password="basemine"开发者_JAVA百科 -D basemine -e "delete from importmusic;"
mysql -u basemine --password="basemine" -D basemine -e "delete from importentetemusic;"
} >> $TRACES/batch/$Mil.$batch.log 2>&1
When I run this batch, its answer is:
/home/mmoine/sgbd_mysql/batch/importMusic.sh: line 51: /batch/20100319160018.afce01aa.cr.log: Aucun fichier ou répertoire de ce type
______ (in english, I suppose: "No files or Directory found")
So, please, how can I put all generated messages in this log file?
Thanks for your answers.
Sorry for my english ;)you should define your TRACES
variable. Also, use $()
instead of backticks whenever possible.
TRACES="something here"
Mil=$(date +"%Y%m%d%H%M%S")
batch="${DatMusic}"
TabimportEnteteMusic="importentetemusic.dat"
{
grep '^ENTETE' "${IMPORT}/${DatMusic}" > "${IMPORT}/$TabimportEnteteMusic"
mysql -u basemine --password="basemine" -D basemine -e "delete from importmusic;"
mysql -u basemine --password="basemine" -D basemine -e "delete from importentetemusic;"
} >> $TRACES/batch/${Mil}.${batch}.log 2>&1
The error message speaks about the /batch/20100319160018.afce01aa.cr.log file.
This means that $TRACES/batch/${Mil}.${batch}.log is replaced by /batch/20100319160018.afce01aa.cr.log
This means that the $TRACES variable can't be defined at the place you are using it (event if you repeat one hundred times "$TRACE is an environment variable and is defined").
Try a
echo "\$TRACES $TRACES"
$TRACES/batch/$Mil.$batch.log
is becoming /batch/20100319160018.afce01aa.cr.log
so I guess $TRACES
isn't defined.
I guess the /batch
directory doesn't exist.
精彩评论