Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I will run the following script:

#!/bin/bash
./myprogram

#get exit code
exitvalue=$?

#log exit code value to /var/log/messages
logger -s "exit code of my program is " $exitvalue

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

How should I modify logger command above?

share|improve this question

3 Answers

$ man logger

Logger provides a shell command interface to the syslog(3) system log module.

You'll need to change your syslog configuration if you want it to log things to other places. You could establish a certain facility that has an output file in your home directory, for example. You would need to be root to do that, though.

share|improve this answer

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
share|improve this answer

If you want to use logger so that the message appears both in the system logs and in some file of yours, you might do

  logger -s your message 2>&1 $HOME/somefile

since the -s option to logger also outputs on stderr which is redirected with 2>&1

share|improve this answer
How about exitvalue=$? ? where should i insert it above? – alwbtc Nov 27 '12 at 20:30
@Basile Starynkevitch I use this command, it shows on STDOUT. But it didn't save in the givwn file . Why ? – devsda Mar 12 at 19:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.