本文介绍了如何使用logger命令登录到Linux中的特定文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将运行以下脚本:
#!/bin/bash
./myprogram
#get exit code
exitvalue=$?
#log exit code value to /var/log/messages
logger -s "exit code of my program is " $exitvalue
但是我不希望在/var/log/messages
中写入日志消息,因为我没有root特权.相反,我希望将其写入我的主目录中的文件中:/home/myuser/mylog
But I don't want log message to be written in /var/log/messages
because I don't have root privileges. Instead I want it to be written to a file in my home directory: /home/myuser/mylog
如何修改上面的logger
命令?
推荐答案
我不认为您真的需要(或不想)为此加入logger
/syslog
.只需将脚本的最后一行替换为:
I don't think you really need to (or want to) involve logger
/syslog
for this. Simply replace the last line of the script with:
echo "Exit code of my program is $exitvalue" >> /some/file/that/you/can/write/to
这篇关于如何使用logger命令登录到Linux中的特定文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!