| 1 | = Write Naemon Log = |
| 2 | |
| 3 | We can write to naemon.log file by issue command |
| 4 | {{{ |
| 5 | #!sh |
| 6 | OMD[monitor@501264b41d2d]:~/var/naemon$ pwd |
| 7 | /omd/sites/monitor/var/naemon |
| 8 | OMD[monitor@501264b41d2d]:~/var/naemon$ echo "[$(date +%s)] User Activity msg TEST log" >> naemon.log |
| 9 | }}} |
| 10 | Linux command '''date +%s''' will print time in current time since Epoch 1970 |
| 11 | |
| 12 | In C program, we can implement this function with bash shell via '''system( bash cmd )''' |
| 13 | {{{ |
| 14 | #!C |
| 15 | int writeLogFile( char *msg ) |
| 16 | { |
| 17 | char str_msg[1024]; |
| 18 | sprintf( str_msg, "echo \"[%d] User Activity %s \" >> /omd/sites/monitor/var/naemon/naemon.log",(int)time(NULL), msg); |
| 19 | printf(str_msg); |
| 20 | system(str_msg); |
| 21 | return 0; |
| 22 | } |
| 23 | }}} |
| 24 | |
| 25 | |
| 26 | }}} |