Snippets
TOC
Programming
PHP
Perl
OS command call
with `…`
# Positiv result
$msg = `ping -c 1 green`;
$rc = $?;
print "rc = $rc\n";
print "msg= $msg\n";
# Negativ result
$msg = `ping -c 1 red`;
$rc = $?;
print "rc = $rc\n";
print "msg= $msg\n";
with system()
# Positiv result
$cmd = 'ping -c 1 green';
$msg = system($cmd);
$rc = $?;
print "rc = $rc\n";
print "msg= $msg\n";
# Negativ result
$cmd = 'ping -c 1 red';
$msg = system($cmd);
$rc = $?;
print "rc = $rc\n";
print "msg= $msg\n";
use strict;
use warnings "all";
use Time::Local;
my ($year, $month, $day, $epoch, $wday);
my $file_name = $ARGV[0];
open(LOG, "<$file_name") or die "Cannot open file $file_name\n";
while ( <> ) {
chomp;
if ( m/^(\d\d\d\d-\d\d-\d\d)\s\d\d:\d\d:\d\d\s-\s/ ) {
($year, $month, $day) = split('-', $1);
$month -= 1;
$epoch = timelocal(00, 00, 00, $day, $month, $year);
(undef,undef,undef,undef,undef,undef,$wday,undef,undef) = localtime($epoch);
if ( $wday == 0 || $wday == 6 ) {
print $_ . "\n";
}
}
}
close(LOG);
exit(0);
#!/usr/bin/perl
use strict;
use warnings;
sub deref
{
my $xref = $_[0];
my $yref = $_[1];
foreach (@$xref) {
print $_ . "\n";
}
print "\n";
foreach (@$yref) {
print $_ . "\n";
}
}
my @a = ('a', 'b', 'c');
my @b = ('1', '2', '3');
&deref( \@a, \@b );
exit 0;
#!/usr/bin/perl
use strict;
use warnings;
my @lFiles = glob "*";
foreach ( @lFiles ) {
print $_;
if ( -d $_ ) {
print "is directory\n";
}
else {
print "is NOT directory\n";
}
}</pre>
</td></tr></tbody>
</table>
PL/SQL
CREATE OR REPLACE TRIGGER resumable_session_logon_trigger
AFTER LOGON ON DATABASE
DECLARE
v_sid NUMBER;
v_serial# NUMBER;
v_program VARCHAR2(15);
v_osuser VARCHAR2(16);
v_machine VARCHAR2(12);
v_username VARCHAR2(30);
BEGIN
SELECT sid, serial#, SUBSTR(program, 1, 15), osuser, SUBSTR(machine, 1, 12), username
INTO v_sid, v_serial#, v_program, v_osuser, v_machine, v_username
FROM v$session
WHERE audsid = USERENV('sessionid')
AND sid = (SELECT sid FROM v$mystat WHERE rownum < 2);
-- 15 chars only!!!
-- IF v_program = 'passba5' THEN
-- IF v_machine = 'EWP\NB-91497' THEN
-- IF v_osuser = 'tksdr' THEN
IF v_username ='DAGODP' THEN
EXECUTE IMMEDIATE('ALTER SESSION ENABLE RESUMABLE TIMEOUT 7200 NAME '
|| ''logon trigger resumable session for user '
|| v_username || '''');
END IF;
END;
/
SELECT trigger_name, status, action_type
FROM dba_triggers
WHERE owner = 'SYS'
;
awk
bash/ksh/sh
#!/bin/sh
if test `TZ=CET-24 date +%d` = 1; then
echo "Today IS the last day of month"
else
echo "Today is NOT the last day of month"
fi
Sources / Literature