简体   繁体   English

使用脚本外壳(Linux批处理)和重定向在日志文件中进行交融

[英]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): 我在批处理文件(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" -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. 您应该定义TRACES变量。 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. 该错误消息显示/batch/20100319160018.afce01aa.cr.log文件。

This means that $TRACES/batch/${Mil}.${batch}.log is replaced by /batch/20100319160018.afce01aa.cr.log 这意味着$ TRACES / batch / $ {Mil}。$ {batch} .log被/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"). 这意味着不能在使用位置定义$ TRACES变量(如果您重复一百次,则“ $ TRACE是环境变量并已定义”)。

Try a 尝试一个

echo "\$TRACES $TRACES"

$TRACES/batch/$Mil.$batch.log is becoming /batch/20100319160018.afce01aa.cr.log so I guess $TRACES isn't defined. $TRACES/batch/$Mil.$batch.log变为/batch/20100319160018.afce01aa.cr.log因此我想$TRACES尚未定义。

I guess the /batch directory doesn't exist. 我猜/batch目录不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM