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 prog
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> $HOME/somefile
since the -s
option to logger
also outputs on stderr which is redirected to the file with 2>
You could want to use 2>> $HOME/somefile
to append (not overwrite) your $HOME/somefile
(read about bash redirections), and (see logger(1) for details) you may prefer to pass the program option --id=$$
to logger
.