0

I had a task that I have to write up a simple bash script which in turn executes admin command from Websphere Application Server (WAS). I put it into /etc/cron.daily folder hoping it would be executed in a daily basis (at what time I have no idea). However I want to have a footprint of this script is kicked off by the system so I added echo statement.

#!/bin/bash
[foo command to execute]
echo "foo command is executed" > /bpm/v8/logs/foo.log

Now I have three questions.

  1. There is system log file from WAS (SystemOut.log). Is it possible to write output of echo to SystemOut.log file?
  2. If not, is there a way that I could append date/time stamp to foo.log file?
  3. How can I prevent foo.log file eating up disk space? I know that SystemOut.log file gets compressed saved with date/time stamp time to time. I think some sort of log rotate(?) program does it.

Context of this problem is in rhel v6 64-bit machine.

  • 1
    Check out the logger command. This may be helpful in your case. Looks like you can use it to interface with system logs or create your own and it handles date time stamp's – mrwhale Jul 20 '16 at 22:13
  • Thanks! I will look up logger command for sure. That sounds promising. – DaeYoung Jul 21 '16 at 13:59
0

The answers to your questions:

  1. If the SystemOut.log file is owned by the same or more privileged account that runs the script, yes you can write to it, but I suggest not doing this, as you may need to provide that log to vendor for troubleshooting a problem one day and foreign entries in the log may throw them off and at the worst case they might refuse to help you because the file integrity was compromised (far chance but not non-existent)

  2. As long as the file/directory ownerships and permissions allow you, you can write this anywhere you want.

  3. You can add this log file to the logrotate scope and it will get recycled in the schedule desired. Or you can add a few lines after echo'ing the log line to scan the file and if it is larger than, say 10K lines, trim the first 9K lines and stash them somewhere in a compressed form. This is totally up to you.

  • Thank you for your detailed explanation. It expanded my scope of understanding in regards to it. – DaeYoung Jul 21 '16 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.