Fantastic! This is one of the threads that keep me coming here again and again.
When i wrote my first post i had the following script as data source for tests (AIX 6.1 last TL):
I understand now why that worked with my redirections but in other more real-life situations they might fail.
My focus is on writing scripts to accomplish tasks and i want my own messages (error and warning/info) to be as tolerant as possible, so here is what i suggest as a solution for writing custom scripts:
- Put a time stamp in every line of output. Even if the lines in the output file will become disorganized, a simple "sort" will put them in order again. I use a certain "output format" for my lines, which is consistent across scripts:
[PID TIMESTAMP MSGCLASS message]
where MSGCLASS is either "Info", "Warning" or "Error".
- Work similar to "syslog": all (error/warning/info) messages to a info log, and error messages also to a separate error log. This way you can avoid the elaborate redirection gymnastics for the usual things you want to achieve.
In bash, I need to send the STDOUT and STDERR from a command to one file, and then just STDERR to another file. Doing one or the other using redirects is easy, but trying to do both at once is a bit tricky. Anyone have any ideas? (9 Replies)
Friends
I have to redirect STDERR messages both to screen and also capture the same in a file.
2 > &1 | tee file works but it also displays the non error messages to file, while i only need error messages.
Can anyone help?? (10 Replies)
Hi friends
I am facing one problem while redirecting the out of the stderr and stdout to a file
let example my problem with a simple example
I have a file (say test.sh)in which i run 2 command in the background
ps -ef &
ls &
and now i am run this file and redirect the output to a file... (8 Replies)
working on a c sell script
I think I understand the concept of it, which is:
filename >> file.txt (to appaend)
or filename | tee -a file.txt (to append)
The problem is that my shell script is used with several parameters, and these commands don't seem to work with just filename. They... (2 Replies)
Hi
I am not if this is possible: is it possible in bach (or another shell) to redirect GLOBALLY the stdout/stderr channels to a file.
So, if I have a script
script.sh
cmd1
cmd2
cmd3
I want all stdout/stderr goes to a file. I know I can do:
./script.sh 1>file 2>&1
OR
... (2 Replies)
Hi,
I already searched through the forum and tried to find a answer for my problem but I didn't found a full working solution, thats way I start this new thread and hope, some can help out.
I wonder that I'm not able to find a working solution for the following scenario:
Working in bash I... (8 Replies)
I originally wrote my script using the korn shell and had to port it to bash on a another server. My script is working find for backing up but noticed that now after the move, I am not getting any output to my log files.
Using Korn shell, this worked for me for some odd reason. This was sending... (2 Replies)
Dear all,
redirecting STDOUT & STDERR to file is quite simple, I'm currently using:
exec 1>>/tmp/tmp.log; exec 2>>/tmp/tmp.logBut during script execution I would like the output come back again to screen, how to do that?
Thanks
Lucas (4 Replies)
Hi folks
I need/want to redirect output (stdout, stderr) from an exec call to separate files. One for stderr only and two(!) different (!) ones for the combined output of stderr and stdout.
After some research and testing i got this so far :
(( exec ${command} ${command_parameters} 3>&1... (6 Replies)
Dear all,
redirecting STDOUT & STDERR to file is quite simple, I'm currently using:
Code:
exec 1>>/tmp/tmp.log; exec 2>>/tmp/tmp.log
But during script execution I would like the output come back again to screen, how to do that?
Thanks
Luc
edit by bakunin: please use CODE-tags like the... (6 Replies)
Discussion started by: tmonk1
6 Replies
LEARN ABOUT DEBIAN
perlbal::manual::logging
Perlbal::Manual::Logging(3pm) User Contributed Perl Documentation Perlbal::Manual::Logging(3pm)NAME
Perlbal::Manual::Logging - How Perlbal's logging system works
VERSION
Perlbal 1.78.
DESCRIPTION
Perlbal supports logging of a few messages (and you can log your messages in your plugins, for instance).
This document describes how to achieve that.
IMPORTANT: foreground vs. background
If Perlbal is running on the foreground, it logs by calling "printf", which means you should get the logs on "STDOUT".
If Perlbal is running on the background, it logs through Sys::Syslog. If Sys::Syslog is not available, there will be no logging, and THAT'S
THE MOST IMPORTANT THING TO KNOW ABOUT PERLBAL'S LOGGING SYSTEM.
How to log a message
You can log a message by calling "Perlbal::log" as you'd call Sys::Syslog's "syslog":
Perlbal::log( $priority, $format, @args );
You should read the documentation for Sys::Syslog for more information, but here's an example:
Perlbal::log( 'info', 'beginning run' );
And here's another example:
Perlbal::log( 'crit', "this thing crashed: $!" );
What is logged?
o When we try to read from or write to a filehandle that is undefined, Perlbal::AIO logs a critical message:
Perlbal::log("crit", "Undef $fh: $stack_trace");
o When failing to create a socket, Perlbal::BackendHTTP logs a critical message:
Perlbal::log('crit', "Error creating socket: $!");
o When "inet_aton" fails to create a socket, Perlbal::BackendHTTP logs a critical message:
Perlbal::log('crit', "inet_aton failed creating socket for $ip");
o When writing to a client, if we try to read more than we should from the backend, Perlbal::ClientHTTPBase logs a warning message:
Perlbal::log('warning', "tried to readahead negative bytes. filesize=$self->{reproxy_file_size}, offset=$self->{reproxy_file_offset}");
o When opening a file being PUT for writing to disk, if there's an error (which is going to originate a 500 server error),
Perlbal::ClientHTTPBase logs a warning message:
Perlbal::log('warning', "system error: $msg ($info)");
o If we receive a request with a content length different from the actual length of the request, Perlbal::ClientProxy logs a critical
message:
Perlbal::log('crit', "Content length of $clen declared but $self->{buoutpos} bytes written to disk");
o When trying to buffer data to disk, if the operation fails Perlbal::ClientProxy logs a critical message:
Perlbal::log('crit', "Failure to open $fn for buffered upload output");
o After buffering data to disk, if the file is empty, Perlbal::ClientProxy logs a critical message:
Perlbal::log('crit', "Error writing buffered upload: $!. Tried to do $len bytes at $self->{buoutpos}.");
o When purging a buffered upload on the disk, if an error occurs, Perlbal::ClientProxy logs a critical message:
Perlbal::log('warning', "Unable to link $self->{bufilename}: $!");
o When marking a backend as pending, if there's already another one in that ip/port, Perlbal::Service will log a couple of warning
messages:
Perlbal::log('warning', "Warning: attempting to spawn backend connection that already existed.");
Perlbal::log('warning', " -- [$filename:$line] $package::$subroutine");
o When deciding whether we should spawn one or more backend connections, if the total of pending conections is negative, Perlbal::Service
will log a critical message:
Perlbal::log('crit', "Bogus: service $self->{name} has pending connect count of $self->{pending_connect_count}?! Resetting.");
o When spawning a backend connection, if there is no IP address for the backend, Perlbal::Service will log a critical message:
Perlbal::log('crit', "No backend IP for service $self->{name}");
o When starting, Perlbal will log an info message:
Perlbal::log('info', 'beginning run');
o When shutting down, Perlbal will log an info message:
Perlbal::log('info', 'ending run');
o After each loop, is some error occurred, Perlbal will log a critical message:
Perlbal::log('crit', "crash log: $_") foreach split(/
?
/, $@);
o When attempting to create the pidfile, if unsuccessful, Perlbal will log an info message:
Perlbal::log('info', "couldn't create pidfile '$file': $!" );
o When attempting to write to the pidfile, if unsuccessful, Perlbal will log an info message:
Perlbal::log('info', "couldn't write into pidfile '$file': $!" );
Generating more logs by sending a USR1 signal to perlbal
If you send a USR1 signal to perlbal, that tells it to log some basic statistics to the syslog.
It's similar to connecting to a management service and issue a "show service" for each service, plus a "states" and a "queues" commands.
Where is it logged to?
The way Perlbal opens Sys::Syslog, it logs to /var/log/daemon.log by default.
SEE ALSO
You can tweek Sys::Syslog's configuration under /etc/syslog.conf. See Sys::Syslog for more details.
perl v5.14.2 2012-03-23 Perlbal::Manual::Logging(3pm)