unix - Setting Up log for a bash script -
i have bash script want run daemon checks condition work , sleeps time , cycle repeats.
i demonize script : nohup myscript.sh &
how can setup logging same script has same echo commands prints statements , how make sure have pid of script if want kill later.
can suggest how can achieve same
if @ i/o redirection chapter in advanced bash-scripting guide, see can redirect output file doing like, in top of script:
exec 2>&1 exec 1>>out.log
the first line redirects stderr stdout, , second line appends stdout out.log. if this, can use echo write specific messages log-file, , output of commands, haven't silenced written log-file well.
bash has lot of special variables, can overview of these in special shell variables reference card. 1 of these $$
, hold scripts pid. save this, can following:
echo $$ > ${0}.pid
this create file name <file name of script>.pid
, containing pid of script.
Comments
Post a Comment