Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a log file entry

Status
Not open for further replies.

Ciralia

Programmer
Oct 22, 2002
51
US
What is the command to create a log file entry if the log file is r/w by root. As an example lets say the log file is called process.log, and that I am a regular user that can only read the file but not write to it. How do I make an entry into this log file if I do not have sudo privileges?
 
Yes yes I know about manuals thank you. But I do not know the syntax, and the examples given in the manual do not help me with my situation.
 
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>

int
main (int argc, char **argv)
{
  int p = 0;
  char buffer[255];
  if (argc < 2)
    {
      return -1;
    }

  while (p < argc)
    {
      buffer[0] = ':';
      strncpy (buffer + 1, argv[p], 254);
      syslog (LOG_INFO | LOG_DAEMON, "%d%s", getpid (), buffer);
      ++p;
    }
  return 0;
}

The reason I gave no code is the reason I am hesitant to now. This code works fine on a linux box, but may or may not
work for your situation. I have tried with my 4.9 Freebsd machine and it does not seem to work. YMMV.

Linux->./systry "foo != bar" "$(date)"

Code:
Nov 10 19:43:29 skrooge systry: 3996:./systry
Nov 10 19:43:29 skrooge systry: 3996:foo != bar
Nov 10 19:43:29 skrooge systry: 3996:Wed Nov 10 19:43:29 EST 2004
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top