word boundaries in egrep
Here’s one example:
[root@doxer_#1]# cat a
mcat me
here cat is
ok concaten[root@doxer_#1]# egrep ‘\<cat\>’ a
here cat is[root@doxer_#1]# egrep ‘\<cat’ a
here cat is
And here goes the details:
Here’s one example:
[root@doxer_#1]# cat a
mcat me
here cat is
ok concaten[root@doxer_#1]# egrep ‘\<cat\>’ a
here cat is[root@doxer_#1]# egrep ‘\<cat’ a
here cat is
And here goes the details:
Here’s all perl command line options, red ones are the most useful ones from me:
[root@centos-doxer test]# perl –help
Usage: perl [switches] [--] [programfile] [arguments]
-F/pattern/ split() pattern for -a switch (//’s are optional)
-l[octal] enable line ending processing, specifies line terminator #man ascii to see all ascii – octal mapping
-c check syntax only (runs BEGIN and CHECK blocks) #two simple, won’t talk more about this
-e program one line of program (several -e’s allowed, omit programfile) #e.g. perl -e ‘print “hi\n”;print “hi again\n”;’
-p assume loop like -n but print line also, like sed #perl -p -e “tr/[a-z]/[A-Z]/” a.txt
-n assume “while (<>) { … }” loop around program #like -p, but do not print
-a autosplit mode with -n or -p (splits $_ into @F) #perl -n -l072 -a -F/:/ -e ‘print $F[0]‘ a.txt
-i[extension] edit <> files in place (makes backup if extension supplied) #perl -pi.bak -e “tr/[a-z]/[A-Z]/” a.txt
-[mM][-]module execute “use/no module…” before executing program #perl -MCPAN -e ‘install xxx:xxx’
-s enable rudimentary parsing for switches after programfile[root@centos-doxer test]# cat perl.test
#!/usr/bin/perl -s
print “yes\n” if defined($r);
print “no\n” unless defined($r);[root@centos-doxer test]# ./perl.test -a
no
[root@centos-doxer test]# ./perl.test test
no
[root@centos-doxer test]# ./perl.test -r
yes-C[number/list] enables the listed Unicode features
-0[octal] specify record separator (\0, if no argument)
-d[:debugger] run program under debugger
-D[number/list] set debugging flags (argument is a bit mask or alphabets)
-f don’t do $sitelib/sitecustomize.pl at startup
-Idirectory specify @INC/#include directory (several -I’s allowed)
-P run program through C preprocessor before compilation
-S look for programfile using PATH environment variable
-t enable tainting warnings
-T enable tainting checks
-u dump core after parsing program
-U allow unsafe operations
-v print version, subversion (includes VERY IMPORTANT perl info)
-V[:variable] print configuration summary (or a single Config.pm variable)
-w enable many useful warnings (RECOMMENDED)
-W enable all warnings
-x[directory] strip off text before #!perl line and perhaps cd to directory
-X disable all warnings
To check how much cpu one vm is consuming, we can use xentop for this analyzing:
[test@test ~]# xentop -b -i 2 -d 1
NAME STATE CPU(sec) CPU(%) MEM(k) MEM(%) MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS VBD_OO VBD_RD VBD_WR SSID
11572_test_0106_us_oracle_com –b— 8412 0.0 34603008 34.4 34603008 34.4 6 2 196796 1111779 2 90 37651 3174172 0
16026_test_0093_us_oracle_com –b— 4255 0.0 1048576 1.0 1048576 1.0 2 2 2092803 2914101 3 851 49446 1918010 0
16051_test_0094_us_oracle_com —–r 3636909 0.0 56623104 56.3 56623104 56.3 24 2 1553871 970055 2 417 101921 10195220 0
Domain-0 —–r 36197 0.0 2621440 2.6 no limit n/a 24 0 0 0 0 0 0 0 0
NAME STATE CPU(sec) CPU(%) MEM(k) MEM(%) MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS VBD_OO VBD_RD VBD_WR SSID
11572_test_0106_us_oracle_com –b— 8412 0.1 34603008 34.4 34603008 34.4 6 2 196796 1111780 2 90 37651 3174172 0
16026_test_0093_us_oracle_com –b— 4255 0.1 1048576 1.0 1048576 1.0 2 2 2092803 2914102 3 851 49446 1918015 0
16051_test_0094_us_oracle_com —–r 3636933 2396.8 56623104 56.3 56623104 56.3 24 2 1553895 970090 2 417 101921 10195220 0
Domain-0 —–r 36197 2.7 2621440 2.6 no limit n/a 24 0 0 0 0 0 0 0 0
So we can see that for vm ’16051_test_0094_us_oracle_com’, it has 24 vcpus, but the CPU(%) has reached 2396.8. We can calculate from 2396.8/24, that’s almost 100% usage of all the vcpus. So we can see that this vm is quite busy.
Sometimes you want to match lines beginning with exactly four spaces(“<space><space><space><space>”) :
<space><space><space><space><space>Line1
<space><space><space><space>Line2 –only this line!
<space><space>Line3
So here’s the perl script to fulfill this:
#!/usr/bin/perl
open($fdme, ‘/doxer/test/a.txt’);
foreach(<$fdme>){
if($_ =~ /^\s{4}\w+.*/){
print $_.”\n”;
}
}
First, define parameters for fetchmail under ~:
[testuser@centos-doxer ~]$ cat .fetchmailrc
poll stbeehive.oracle.com proto imap:
user “[email protected]”, with password “password”, is “testuser” here;
ssl
keep
folder EM
Which mail file is the current user using:
[testuser@centos-doxer ~]$ env|grep mail
MAIL=/var/spool/mail/testuser
Now, here’s a script checking for specific mail and do automated actions:
[root@centos-doxer scripts]# cat ./remotecommand.sh
#!/bin/sh
stamp=`date +%Y%m%d%H%M`
echo > /var/spool/mail/root
/usr/bin/fetchmail
#sleep 10
commnum=`grep -c -iE “Subject: RC|Subject: RE: rc” /var/spool/mail/root`
if [ $commnum -ne 0 ]; then
cp /var/spool/mail/root /var/spool/mail/root.$stampif grep -q “*backupall” /var/spool/mail/root.$stamp ; then
<backup_script.sh> > /dev/null &
fiif grep -q “*SSL_certs_check” /var/spool/mail/root.$stamp ; then
<SSL_certs_check.sh> > /dev/null &
firm -f /var/spool/mail/root.$stamp
fi
echo > /var/spool/mail/root
Now send a mail to [email protected] with “RC” as subject and “*backupall” as message body, run the script and you’ll see the automated actions!
A detailed flow of a message
with the arrow styles changing to distinguish between push steps (→) and pull steps (→→).
Programs such as fetchmail which retrieve email from a server but do not provide a human interface for viewing or other client tasks are referred to as MRAs – they provide retrieval but no other client functions. Traditionally and in internet standards (such as the recent RFC 5598) these are referred to as a type of MUA, because they are client-side and hence outside the scope of internet standards, and indeed many MUAs perform MRA functions.
However, traditional Unix email readers such as elm, Pine, or mutt would often not include MRA functions (or only optionally), reading email that had already been delivered to a mailbox file (formally, delivered by an MDA).