Write file over network

Hello Forum,

I have an embedded Busybox system with ash shell. On this system is a service with logging output. I want to have this logfile on another computer. This service creates the log file, but I can specify the filename via parameter. The memory is very fast filled up. What could be the easiest way to transfer this file on the fly to another linux machine? I cant install much additional software. I want to run the service for hours, without starting&stopping the service when the space is used.

I thought something like starting the service and writing the log into the file, but transferring the data with netcat to another machine. Where a second netcat instance writes it to hd. If I specify - as filename (for writing the log to stdout), the service only creates a file called --01.log in the current directory. I only need a hint that directs me into the correct direction.

Thanks a lot
Peter

Your problem is not unique and it has been solved long time ago. Configure busybox syslogd to send message logs to a remote logging service (a remote server).

If you want to rediscover the wheel on you own. Setup a log rotation policy in busybox and then send the rotated archive to another server using rsync or scp.

1 Like

Its not this kind of log. Its a plain file created by a program. There is nothing in the syslog.
The system has only 2MB free flash drive and 60MB ram. mounting nfs is not supported.

If you have the logger program installed you could write a small script reading the log file, creating syslog messages out of it and then truncate the log file accordingly. If the program is creating the logfile by redirectio you could even use a pipe and forego the logfile completely:

/my/app > /some/log    # turn that into:
/my/app | /some/script_with_logger

logger is part of many Linux distributions and is used to create syslog messages from the commandline.

I hope this helps.

bakunin

1 Like

I have found a netcat/named pipe solution:

// On my linux laptop, write the logfile to disk:

netcat -l -p 16674 > log.txt

// On the busybox machine
// Create named pipe:

mknod /mnt/np.log p

// Read from the named pipe and write it to the latop:

cat < /mnt/np.log | netcat 192.168.1.2 16674

// Start the service

theservice -write-log /mnt/np.log

------ Post updated at 08:25 AM ------

Close Thread

Be vary tho.
Named pipes have limited buffer size, which depend on operating system and its implementation.

If you are sure those limits won't be hit and remote host will always work....
Otherwise you risk losing logs.

This is reinventing the wheel so to say, a real crude way to ship logs.

Also, using single redirection ... > log.txt , will if a linux laptop process is restarted overwrite log.txt, causing again past log loss.

As bakunin mentioned, a logger facility will be much more robust, configurable and is in the standard.

Regards
Peasant.

1 Like

Its a unreliable solution. But currently I only want to see what could be logged.