• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

unix logs

Hi ,

I am writing few shell scripts to process a txt files , say 1.sh , 2.sh and 3.sh
I need to capture all logs in /var/log/messages using logger
Is it possible i can write some function/configuration to capture all logs in all  the shellscripts without adding echo or logger in the shell scripts.
Or please advice good way of capturing logs of all scripts
I am using Linux .

Thanks
0
magento
Asked:
magento
  • 4
  • 4
  • 2
  • +1
2 Solutions
 
omarfaridCommented:
You can always redirect stdout & sterr to a file like:

1.sh >> /tmp/mylog 2>&1
0
 
magentoAuthor Commented:
Omar,

My company looking for a centralised logs . eg.a property file for putting INFO,FATAL,ERROR etc ?  like log4j in java
can we use log4sh for a centralised logging
https://sites.google.com/a/forestent.com/projects/log4sh

Thanks
0
 
omarfaridCommented:
I never used log4sh before, but from the link provided it seems to be what you want.

You can download and install on your system and use it for some time to see if its really meeting your requirements.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
gheistCommented:
You can filter logs by content of log lines in syslog-ng and rsyslog. shell is very inefficient, probably less interpreted languages like perl or python can come handy.
0
 
TintinCommented:
If you just want a simple way to log all output from a script, then just add

exec >>/var/log/$(basename $0).log 2>&1

Open in new window


to the top of each script.
0
 
magentoAuthor Commented:
Hi Tintin,

Thank you. It will log all the errors too right ?
If yes, i can create a new shell script named log.sh and add the above code which you mentioned.
Later source the log.sh on all of the shell scripts right ? So it will capture all the logs.
I will keep this as an option , but since my company need a centralised log monitoring like log4perl in perl , could you please check if log4sh is vulnerable or i can use it for my project?

Thanks
0
 
gheistCommented:
vulnerable how?
I think it is incapable of processing debug logs from any network device. You must use at least system of capable accomodating that like splunk or greylog2.
0
 
magentoAuthor Commented:
Hi Gheist,

I am going to use the log4sh only for my few shell scripts. So i want to make sure that the log4sh is not an vulnerable and i can use it for one of my customer .
0
 
gheistCommented:
How would it chew 2GB/min from 96-port cisco switch?
0
 
magentoAuthor Commented:
Sorry , i dont understand your question.

Anyway i will try install log4sh and let you know any issues.
0
 
gheistCommented:
I suspect that shell-based log analyser will not sustain any reasonably massive flow of logs.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now