Skull
Skull

Reputation: 167

How can I tail a log file and add command: word on every line before output in a different file?

trying to tail and grep certain logs with $installingFil and adding Command: word before output in $DNLOGfile, but file is empty /private/tmp/DownLog.log What will be the correct approach to echo "Command:" before every line.

I am not able to add/echo "Command:" word before every line which is output in /private/tmp/DownLog.log

like:-

Command: bla bla   
Command: downloding finish

Scrip -

#!/bin/bash
downFil=$(tail -f /var/log/system.log | grep 'Downloading files of')
        
dLog="/private/tmp/DownLog.log"
        
if [ -f /var/log/system.log ]; then
 echo "Command:" "$downFil" >> "$dLog" # dLog is blank
else
 echo "Command: Please wait.." >> $dLog # this works fine
fi

 

Upvotes: 0

Views: 612

Answers (1)

Pierre François
Pierre François

Reputation: 6083

If I understand you correctly, you should try:

tail -f /var/log/system.log | grep 'Downloading files of' | sed 's/^/Command: /' >> /private/tmp/DownLog.log

Upvotes: 1

Related Questions