Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

unix logs

Posted on 2015-01-04
11
Medium Priority
?
350 Views
Last Modified: 2015-01-19
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
Comment
Question by:magento
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 1000 total points
ID: 40531023
You can always redirect stdout & sterr to a file like:

1.sh >> /tmp/mylog 2>&1
0
 
LVL 5

Author Comment

by:magento
ID: 40531031
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 40531128
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 62

Expert Comment

by:gheist
ID: 40531381
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
 
LVL 48

Accepted Solution

by:
Tintin earned 1000 total points
ID: 40532490
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
 
LVL 5

Author Comment

by:magento
ID: 40532878
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
 
LVL 62

Expert Comment

by:gheist
ID: 40532932
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
 
LVL 5

Author Comment

by:magento
ID: 40532934
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
 
LVL 62

Expert Comment

by:gheist
ID: 40532960
How would it chew 2GB/min from 96-port cisco switch?
0
 
LVL 5

Author Comment

by:magento
ID: 40543097
Sorry , i dont understand your question.

Anyway i will try install log4sh and let you know any issues.
0
 
LVL 62

Expert Comment

by:gheist
ID: 40543170
I suspect that shell-based log analyser will not sustain any reasonably massive flow of logs.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question