Log4perl configuration is not working - linux

I have Log4perl installed on my Linux machine and have the following /path/to/log4perl.conf:
log4perl.logger.Fizz = INFO, FizzAppender
log4perl.logger.Buzz = INFO, BuzzAppender
log4perl.appender.FizzAppender = Log::Dispatch::FileRotate
log4perl.appender.FizzAppender.filename = /my/logs/fizz-log.txt
log4perl.appender.FizzAppender.max = 1
log4perl.appender.FizzAppender.DatePattern = yyyy-MM-dd
log4perl.appender.FizzAppender.TZ = EST
log4perl.appender.FizzAppender.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.FizzAppender.layout.ConversionPattern = %d %m %n
log4perl.appender.BuzzAppender = Log::Dispatch::FileRotate
log4perl.appender.BuzzAppender.filename = /my/logs/buzz-log.txt
log4perl.appender.BuzzAppender.max = 1
log4perl.appender.BuzzAppender.DatePattern = yyyy-MM-dd
log4perl.appender.BuzzAppender.TZ = EST
log4perl.appender.BuzzAppender.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.BuzzAppender.layout.ConversionPattern = %d %m %n
Inside each of my perl scripts (each script uses a different appender and a logs to a different log file):
use Log::Log4perl;
my $log_conf = "/path/to/log4perl.conf";
Log::Log4perl::init($log_conf);
# In one script the logger is a "Fizz" logger (like below), and in the other
# script the logger is a "Buzz" logger.
my $logger = Log::Log4perl->get_logger("Fizz");
$logger->info("This should work.");
Even though each script uses a different appender and logs to a different file, they should all have the same behavior:
Each log gets rotated once a day, and old (rotated) logs gets deleted
I've had this script running for more than 24 hours now, and I don't see any logs being generated under /my/logs/.
So I ask: is my log4perl.conf incorrect? If not, what can I do to diagnose the issue? Am I initializing the library incorrectly in the perl scripts? Thanks in advance.

I think you need to add the parameter mode to your log4perl.conf file:
log4perl.appender.FizzAppender.mode = truncate
log4perl.appender.BuzzAppender.mode = truncate
To speed things along I've changed your DatePattern to the following:
log4perl.appender.FizzAppender.DatePattern = yyyy-MM-dd-HH-MM
log4perl.appender.BuzzAppender.DatePattern = yyyy-MM-dd-HH-MM
Here's a test using your log4perl.conf file. I've created 2 copies of your Perl script:
log4perl_Buzz.pl
log4perl_Fizz.pl
I've added a loop within the scripts so that every second they log a message to their respective log files:
while (1) {
$logger->info("This should work.");
sleep 1;
}
I run them both at the same time and see the following results using a watch ls -l:
Every 2.0s: ls -l Thu Dec 20 21:16:51 2012
total 12
-rwxrwxr-x 1 saml saml 358 Dec 20 20:15 log4perl_Buzz.pl
-rw-rw-r-- 1 saml saml 978 Dec 20 21:07 log4perl.conf
-rwxrwxr-x 1 saml saml 358 Dec 20 20:15 log4perl_Fizz.pl
After I run the 2 scripts:
Every 2.0s: ls -l Thu Dec 20 21:17:56 2012
total 20
-rw-rw-r-- 1 saml saml 39 Dec 20 21:17 buzz-log.txt
-rw-rw-r-- 1 saml saml 39 Dec 20 21:17 fizz-log.txt
-rwxrwxr-x 1 saml saml 358 Dec 20 20:15 log4perl_Buzz.pl
-rw-rw-r-- 1 saml saml 978 Dec 20 21:07 log4perl.conf
-rwxrwxr-x 1 saml saml 358 Dec 20 20:15 log4perl_Fizz.pl
After ~2 minutes pass:
Every 2.0s: ls -l Thu Dec 20 21:19:05 2012
total 28
-rw-rw-r-- 1 saml saml 195 Dec 20 21:19 buzz-log.txt
-rw-rw-r-- 1 saml saml 2340 Dec 20 21:18 buzz-log.txt.1
-rw-rw-r-- 1 saml saml 234 Dec 20 21:19 fizz-log.txt
-rw-rw-r-- 1 saml saml 2301 Dec 20 21:18 fizz-log.txt.1
-rwxrwxr-x 1 saml saml 358 Dec 20 20:15 log4perl_Buzz.pl
-rw-rw-r-- 1 saml saml 978 Dec 20 21:07 log4perl.conf
-rwxrwxr-x 1 saml saml 358 Dec 20 20:15 log4perl_Fizz.pl
Here's my version of log4perl.conf for those that are playing at home 8-).
log4perl.logger.Fizz = INFO, FizzAppender
log4perl.logger.Buzz = INFO, BuzzAppender
log4perl.appender.FizzAppender = Log::Dispatch::FileRotate
log4perl.appender.FizzAppender.filename = fizz-log.txt
log4perl.appender.FizzAppender.max = 1
log4perl.appender.FizzAppender.DatePattern = yyyy-MM-dd-HH-MM
log4perl.appender.FizzAppender.TZ = EST
log4perl.appender.FizzAppender.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.FizzAppender.layout.ConversionPattern = %d %m %n
log4perl.appender.FizzAppender.mode = truncate
log4perl.appender.BuzzAppender = Log::Dispatch::FileRotate
log4perl.appender.BuzzAppender.filename = buzz-log.txt
log4perl.appender.BuzzAppender.max = 1
log4perl.appender.BuzzAppender.DatePattern = yyyy-MM-dd-HH-MM
log4perl.appender.BuzzAppender.TZ = EST
log4perl.appender.BuzzAppender.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.BuzzAppender.layout.ConversionPattern = %d %m %n
log4perl.appender.BuzzAppender.mode = truncate
These were useful resources in figuring this out:
Log::Dispatch::FileRotate on CPAN
log4perl FAQ
Limiting log size with log4perl - stackoverflow

Related

Unable to run cron job with standard user account

The same job can be executed as root, but it can't execute as a standard user.
Is it permission problem or I need to change anything, I have no idea on it.
Thanks
SunOS 5.10 Generic_150400-30 sun4v sparc SUNW,SPARC-Enterprise-T5120
Command:
1) login as a root
2) crontab -l
* * * * * /usr/bin/date > /tmp/root.log
3) /tmp/root.log is here
1) login as a Non-root user
2) crontab -l
* * * * * /usr/bin/date > /tmp/non-root.log
3) /tmp/non-root.log is not here
The following permissions are OK for the binary file date
-bash-3.2# ls -l /usr/bin/date
-r-xr-xr-x 1 root bin 11056 Jan 22 2005 /usr/bin/date
-bash-3.2#
If the permissions are OK check your cron log on /var/cron/log file
-bash-3.2# tail /var/cron/log
< root 24592 c Fri Oct 20 18:50:21 2017
> CMD: /usr/bin/date > /tmp/non-root.log
> user 25192 c Fri Oct 20 18:51:00 2017
< user 25192 c Fri Oct 20 18:51:00 2017
> CMD: /scripts/collectdata.sh > /dev/null 2>&1
> root 25769 c Fri Oct 20 18:52:00 2017
< root 25769 c Fri Oct 20 18:52:00 2017
> CMD: /scripts/collectdata.sh > /dev/null 2>&1
> root 26853 c Fri Oct 20 18:54:00 2017
< root 26853 c Fri Oct 20 18:54:00 2017
-bash-3.2#
Thanks all, I finally found out the issue.
The reason is that non-root account is locked out, I think it maybe someone did many failure attempt which make this locked.
After I passwd -u "Account", the job can be run as expected. Thanks~

How to check if a locale is UTF-8?

I'm working with Yocto to create an embedded linux distribution for an ARM device (i.MX 6Quad Processors).
I've configured the list of desired locales with the variable:
IMAGE_LINGUAS = "de-de fr-fr en-gb en-gb.iso-8859-1 en-us en-us.iso-8859-1 zh-cn"
As result I've obtained a file systems that contains the following folders:
root#lam_icu:/usr/lib/locale# cd /usr/share/locale/
root#lam_icu:/usr/share/locale# ls -la
total 0
drwxr-xr-x 6 root root 416 Nov 17 2016 .
drwxr-xr-x 30 root root 2056 Nov 17 2016 ..
drwxr-xr-x 4 root root 296 Nov 17 2016 de
drwxr-xr-x 3 root root 232 Nov 17 2016 en_GB
drwxr-xr-x 4 root root 296 Nov 17 2016 fr
drwxr-xr-x 4 root root 296 Nov 17 2016 zh_CN
and:
root#lam_icu:/usr/share/locale# cd /usr/lib/locale/
root#lam_icu:/usr/lib/locale# ls -la
total 0
drwxr-xr-x 9 root root 640 Mar 13 2017 .
drwxr-xr-x 32 root root 40000 Mar 13 2017 ..
drwxr-xr-x 3 root root 1016 Mar 13 2017 de_DE
drwxr-xr-x 3 root root 1016 Mar 13 2017 en_GB
drwxr-xr-x 3 root root 1016 Mar 13 2017 en_GB.ISO-8859-1
drwxr-xr-x 3 root root 1016 Mar 13 2017 en_US
drwxr-xr-x 3 root root 1016 Mar 13 2017 en_US.ISO-8859-1
drwxr-xr-x 3 root root 1016 Mar 13 2017 fr_FR
drwxr-xr-x 3 root root 1016 Mar 13 2017 zh_CN
Which is the encoding of all non ISO-8859-1 locales? Can I assume that "en_GB" or "en_US" use the UTF-8 encoding?
I've tried to open the "LC_IDENTIFICATION" file, the result is:
Hc�������������cEnglish locale for the USAFree Software
Foundation,
Inc.http://www.gnu.org/software/libc/bug-glibc-locales#gnu.orgEnglishUSA1.02000-06-24en_US:2000en_US:2000en_US:2000en_US:2000en_US:2000en_US:2000en_US:2000en_US:2000en_US:2000en_US:2000en_US:2000en_US:2000UTF-8
At the end of the file there is something that recalls "UTF-8". Is this enough to assume that the encoding is UTF-8?
How to check if a locale is UTF-8?
LC_IDENTIFICATION doesn't tell you much:
LC_IDENTIFICATION - this is not a user-visible category, it contains information about the locale itself and is rarely useful for users or developers (but is listed here for completeness sake).
You'd have to look at the complete set of files.
There appears to be no standard command-line utility for doing this, but there is a runtime call (added a little later than the original locale functions). Here is a sample program which illustrates the function nl_langinfo:
#include <stdio.h>
#include <locale.h>
#include <langinfo.h>
int
main(int argc, char **argv)
{
int n;
for (n = 1; n < argc; ++n) {
if (setlocale(LC_ALL, argv[n]) != 0) {
char *code = nl_langinfo(CODESET);
if (code != 0)
printf("%s ->%s\n", argv[n], code);
else
printf("?%s (nl_langinfo)\n", argv[n]);
} else {
printf("? %s (setlocale)\n", argv[n]);
}
}
return 0;
}
and some output, e.g., by foo $(locale -a):
aa_DJ ->ISO-8859-1
aa_DJ.iso88591 ->ISO-8859-1
aa_DJ.utf8 ->UTF-8
aa_ER ->UTF-8
aa_ER#saaho ->UTF-8
aa_ER.utf8 ->UTF-8
aa_ER.utf8#saaho ->UTF-8
aa_ET ->UTF-8
aa_ET.utf8 ->UTF-8
af_ZA ->ISO-8859-1
af_ZA.iso88591 ->ISO-8859-1
af_ZA.utf8 ->UTF-8
am_ET ->UTF-8
am_ET.utf8 ->UTF-8
an_ES ->ISO-8859-15
an_ES.iso885915 ->ISO-8859-15
an_ES.utf8 ->UTF-8
ar_AE ->ISO-8859-6
ar_AE.iso88596 ->ISO-8859-6
ar_AE.utf8 ->UTF-8
ar_BH ->ISO-8859-6
ar_BH.iso88596 ->ISO-8859-6
The directory names you're referring to are often (but not required) to be the same as encoding names. That is the assumption made in the example program. There was a related question in How to get terminal's Character Encoding, but it has no useful answers. One is interesting though, since it asserts that
locale charmap
will give the locale encoding. According to the standard, that's not necessarily so:
The command locale charmap gives the name used in localedef -f
However, localedef attaches no special meaning to the name given in the -f option.
localedef has a different option -u which identifies the codeset, but locale (in the standard) mentions no method for displaying this information.
As usual, implementations may (or may not) treat unspecified features in different ways. The GNU C library's documentation differs in some respects from the standard (see locale and localedef), but offers no explicit options for showing the codeset name.

Why linux split program have weird behavior with large files >20GB?

I'm doing the next statement on my ubuntu:
split --number=l/5 /pathToSource.csv /pathToOutputDirectory
If i do a "ls"
myUser#serverNAme:/pathToOutputDirectory> ls -la
total 21467452
drwxr-xr-x 2 myUser group 4096 Jun 23 08:51 .
drwxrwxrwx 4 myUser group 4096 Jun 23 08:44 ..
-rw-r--r-- 1 myUser group 10353843231 Jun 23 08:48 aa
-rw-r--r-- 1 myUser group 0 Jun 23 08:48 ab
-rw-r--r-- 1 myUser group 11376663825 Jun 23 08:51 ac
-rw-r--r-- 1 myUser group 0 Jun 23 08:51 ad
-rw-r--r-- 1 myUser group 252141913 Jun 23 08:51 ae
If i do a "du" over ab and ad files.
$du -h ab ad
0 ab
0 ad
As you can see, split divided the file in a non-homogeneous form.
Anyone know what's going on?
Some unprintable character can hang the split?
Thank you.
Best Regards!
Francisco.
While this is unusual data with an average line length of 114137, I'm not sure that fully describes the issue. Hmm you've 21982648969 of data => each bucket that split is trying to fill is 4396529793. That's larger than 2^32. I wonder do we have a 32 bit overflow. Are you on a 32 bit or 64 bit platform? Looking at the code I don't see an overflow issue TBH. Note you could anonymize and compress the data providing the following file for download somewhere:
tr -c '\n' . < /pathToSource.csv | xz > /pathToSource.csv.xz
It's also worth specifying the version since implementation changed a bit between v8.8 and v8.13
A workarround in groovy:
class Sanitizer {
public static void main(String[] args) {
def textOnly = new File('/path/NoDanger.txt')
def data = new File('/path/danger.txt')
String line = null
data.withReader { reader ->
while ( ( line = reader.readLine() ) != null ){
/*char[] stringToCharArray = line.toCharArray();
for(int i = 0; i < 5; i++ ){
char a = stringToCharArray[i]
int b = Character.getNumericValue(a);
println Integer.toHexString(b)
if (!(b =~ /\w/)) {
println "inside"
} else println "outside"
}*/
String newString = line.replaceAll("[^\\p{Print}]", "");
textOnly << newString+"\n"
}
} //reader
}
}

OCaml error: Unbound module Event

I try to build a short ocaml event example. But when I compile, the error in the title appears.
The question of: unbound module Event error when compiling Ocaml game was not helpful for me.
The system is Kubuntu 14.04 and I installed ocaml over aptitude, so installed packages are:
camlp4, ledit, libfindlib-ocaml, libfindlib-ocaml-dev, liboasis-ocaml, liboasis-ocaml-dev, libodn-ocaml, libodn-ocaml-dev, libtype-conv-camlp4-dev, oasis, ocaml, ocaml-base, ocaml-base-nox, ocaml-compiler-libs, ocaml-doc, ocaml-findlib, ocaml-interp, ocaml-native-compilers, ocaml-nox
The OCaml compiler is version 4.01.0
Here is my short test program.
open Thread;;
open Event;;
let chan = Event.new_channel();;
let a () =
Printf.printf "A waiting...\n";;
let sigRX = Event.receive chan in
Printf.printf "A received over channel\n";
let v = Event.sync sigRx in
Printf.printf "A running\n";
Printf.printf "A done!\n";;
let b () =
Thread.delay 0.8
Printf.printf "B sending...\n";;
let sigTX = Event.send "wake up" in
Event.sync sigTX;
Printf.printf "B done!\n";;
let t_a = Thread.create a ();;
let t_b = Thread.create b ();;
I tried to compile this single file (test.ml) with:
ocamlc -thread unix.cma threads.cma test.ml
The response is:
File "test.ml", line 2, characters 0-10:
Error: Unbound module Event
I googled, found some "thread-using-tips" like: http://caml.inria.fr/pub/docs/manual-ocaml/libthreads.html#c%3Athreads
In /usr/lib/ocaml is an threads folder and an thread.mli. Inside the threads folder there are this files:
-rw-r--r-- 1 root root 487 Jan 2 2014 condition.cmi
-rw-r--r-- 1 root root 487 Jan 2 2014 condition.cmx
-rw-r--r-- 1 root root 1203 Jan 2 2014 event.cmi
-rw-r--r-- 1 root root 1867 Jan 2 2014 event.cmx
-rw-r--r-- 1 root root 421 Jan 2 2014 mutex.cmi
-rw-r--r-- 1 root root 407 Jan 2 2014 mutex.cmx
-rw-r--r-- 1 root root 1859 Jan 2 2014 thread.cmi
-rw-r--r-- 1 root root 1308 Jan 2 2014 thread.cmx
-rw-r--r-- 1 root root 62778 Jan 2 2014 threads.a
-rw-r--r-- 1 root root 47047 Jan 2 2014 threads.cma
-rw-r--r-- 1 root root 1258 Jan 2 2014 threads.cmxa
-rw-r--r-- 1 root root 4145 Jan 2 2014 threadUnix.cmi
-rw-r--r-- 1 root root 1515 Jan 2 2014 threadUnix.cmx
What am I missing? I assume, that the Event is packed in Thread Module?
This command line works for me to get past the unbound module problem.
$ ocamlc -I +threads -c test.ml
There are errors in your code, but I imagine you'll know how to fix them.
This full command line will probably work, but I can't be sure because of the errors:
$ ocamlc -thread -I +threads unix.cma threads.cma test.ml
(There are some higher-level tools for building OCaml programs that you might want to learn about at some point.)

gammu-smsd RunOnReceive script results exit status 2

I want to forward an SMS using gammu-smsd RunOnReceive.
That is the script I want to run (/var/spool/gammu/forward.sh) and it goes perfectly if I run it from a sudoer or using sudo -u gammu -g gammu /var/spool/gammu/forward.sh
#!/bin/bash
SMS_MESSAGES=1
for i in `seq $SMS_MESSAGES`
do
number="SMS_${i}_NUMBER"
text="SMS_${i}_TEXT"
eval "gammu-smsd-inject TEXT my_number_goes_here -text \"${!number}: ${!text}\""
done
And here is the problem I am experiencing:
Thu 2015/01/29 23:08:57 gammu-smsd[2549]: Starting run on receive: /var/spool/gammu/forward.sh IN20150130_000850_00_+37368214400_00.txt
Thu 2015/01/29 23:08:57 gammu-smsd[2154]: Process failed with exit status 2
Output of ls -l /etc/gammu-smsdrc /var/spool/gammu/ /usr/bin/gammu-smsd*:
-rw-r--r-- 1 root root 457 Jan 29 22:44 /etc/gammu-smsdrc
-rwxrwxrwx 1 root root 14336 Jun 10 2012 /usr/bin/gammu-smsd
-rwxrwxrwx 1 root root 51164 Jun 10 2012 /usr/bin/gammu-smsd-inject
-rwxrwxrwx 1 root root 9972 Jun 10 2012 /usr/bin/gammu-smsd-monitor
/var/spool/gammu/:
total 24
drwxrwxrwx 2 gammu gammu 4096 Jan 28 16:02 error
-rwxrwxrwx 1 gammu gammu 189 Jan 29 22:13 forward.sh
drwxrwxrwx 2 gammu gammu 4096 Jan 29 23:08 inbox
-rw-rw-r-- 1 gammu gammu 3702 Jan 29 23:08 log
drwxrwxrwx 2 gammu gammu 4096 Jan 29 23:07 outbox
drwxrwxrwx 2 gammu gammu 4096 Jan 29 23:07 sent
What happens if I just do ./forward.sh (not root) - so all is OK:
gammu-smsd-inject[2606]: Created outbox message OUTC20150029_231213_00_my_number_here_sms0.txt
Written message with ID /var/spool/gammu/outbox/OUTC20150029_231213_00_my_number_here_sms0.txt
Here is my /etc/gammu-smsdrc
# Configuration file for Gammu SMS Daemon
[gammu]
port = /dev/ttyUSB0
connection = at
[smsd]
service = files
logfile = /var/spool/gammu/log
debuglevel = 2
commtimeout = 1
sendtimeout = 15
statusfrequency = 0
outboxformat = unicode
transmitformat = unicode
RunOnReceive = /var/spool/gammu/forward.sh
inboxpath = /var/spool/gammu/inbox/
outboxpath = /var/spool/gammu/outbox/
sentsmspath = /var/spool/gammu/sent/
errorsmspath = /var/spool/gammu/error/
ps -fe | grep gammu:
gammu 2154 1 0 23:05 ? 00:00:02 /usr/bin/gammu-smsd --daemon --user gammu --pid /var/run/gammu-smsd.pid
cubie 2644 2403 0 23:20 pts/0 00:00:00 grep gammu
Please, help
I had the same problem and I solved it this way:
First add gammu user to sudoers, with no password:
type: $ sudo visudo
and add: gammu ALL=(ALL) NOPASSWD: ALL
Then run gammu-smsd as root user:
in /etc/init.d/gammu-smsd
change USER=gammu to USER=root
save it and don't forget to restart daemon: service gammu-smsd restart
In RunOnReceive script add sudo in front of gammu-smsd-inject:
e.g.: sudo gammu-smsd-inject TEXT my_tel_num -text "Hello world!"
I hope this will work for you too!
P.S.: I use Gammu version 1.31.90.

Resources