Tuesday, December 31, 2013

How to compile all your reports in Linux at once




#!/bin/bash
FILES=/home/Mahmoud/Documents/Mibrahime_reports/*
DATABASE='express\aivlpvl@db11'
compile=/u01/app/oracle/middleware/asinst_1/config/reports/bin/rwconverter.sh
batch=yes
stype=rdffile
dtype=repfile
overwrite=yes
compile_all=yes
for f in $FILES
do
  echo "Processing $f file..."
  # take action on each file. $f store current file name
  #echo $f
   $compile userid=$DATABASE batch=$batch source=$f stype=$stype dtype=$dtype overwrite=$overwrite compile_all=$compile_all
done



Wednesday, May 1, 2013

How to overwrite client time in the email using postfix

Introduction:
If you ever received  an email from someone whom do not care about configuring his machine  with the right date, you will find his email in the top of your emails list even if you have received many emails later. Because this email time is in the future, also another situation could happen if you received an  email with a historical date. You will not be able easily to find this email because it is hidden between hundreds of emails in very old date. 

Solution:
I have created a Perl script which will read all emails received by your MTA ( In my situation it will be Postfix ) and change the date to server date.

Steps:
  1. Postfix master files:
We have to edit master file to add  content filter ,  you can call it any name like (myhook) in my example.

#vi /etc/postfix/master.cf

smtp      inet  n       -       n       -       -       smtpd -o content_filter=myhook

myhook unix - n n - - pipe
 flags=DROhu user=nobody argv=/etc/postfix/tml.pl -f ${sender} -d ${recipient}


and also we will need to add another service which will be used by the script to send the emails outside.
127.0.0.1:10025   inet  n       -       n       -       -        smtpd
        -o content_filter=
                -o receive_override_options=no_unknown_recipient_checks
                -o smtpd_helo_required=no
                -o smtpd_helo_restrictions=
                -o smtpd_data_restrictions=
                -o smtpd_client_restrictions=
                -o smtpd_sender_restrictions=
                -o smtpd_recipient_restrictions=permit_mynetworks,reject
                -o mynetworks_style=host
                -o in_flow_delay=0




3-Editing postfix header_check file to prevent sending wrong sender in the header.

#echo "/^Sender:/ IGNORE" >>  /etc/postfix/header_checks

4-Editing main.cf fileWithout this configs master.cf  parameters like (O and D) will not work, these parameters used to allow sending BCC.

# vim /etc/postfix/main.cf

myhook_destination_recipient_limit=1

5-Adding perl Script  and make it exec

#vi /etc/postfix/script.pl



#!/usr/bin/perl
##author: Mahmoud Ibrahim
##Email 1.m.mahmoud@gmail.com
#######  http://www.linkedin.com/profile/view?id=134494584&trk=tab_pro#####
## Version 0.3
##You must have a specific parameters in master.cf and main.cf files to be able to send BCC.
##Please contact me for any help. I tested this script for BCC and cc and TO with attachment 
## and have succedded (Alhamdo Leelah).
##All required parameters could be found in my BLOG :).
##http://e2mm10.blogspot.com
use warnings;
use strict;
use MIME::Lite;
use Net::SMTP;
use Mail::Internet;
my  $sys_time = localtime;
my $message = Mail::Internet->new(\*STDIN);
my $mailbcc=$message->head->get('Delivered-To');
my $mysender=$message->head->get('From');
my $mailrecept=$message->head->get('To');
if ($mailrecept=~ m/undisclosed[a-zA-Z-]/ ) {$message->head->replace("To",$mysender);}
$message->smtpsend(Host =>'127.0.0.1:10025',Bcc=>$mailbcc,MailFrom=>$mysender);



#chmod +x   /etc/postfix/script.pl                                                                                      

5- now we will have to restart postfix and check the log.
#/etc/init.d/postfix restart
#tailf /var/log/maillog



May  1 18:39:31 Mailsrv1 postfix/smtpd[16927]: 5073D39F00DE: client=smtp09.bis7.eu.blackberry.com[178.239.85.14]
May  1 18:39:31 Mailsrv1 postfix/cleanup[16923]: 5073D39F00DE: message-id=<1548046835-1367421534-cardhu_decombobulator_blackberry.rim.net-1130506589-@b14.c19.bise7.blackberry>
May  1 18:39:35 Mailsrv1 postfix/qmgr[14595]: 5073D39F00DE: from=<SRS0=/4fppu=OS=xxxxxxxxxxxx.com.sa=xxxxxxxxxx@srs.bis7.eu.blackberry.com>, size=244565, nrcpt=2 (queue active)
May  1 18:39:35 Mailsrv1 postfix/pipe[16930]: 5073D39F00DE: to=<xxxxxxx@xxxxxxx.com.sa>, relay=myhook, delay=5.2, delays=5.1/0/0/0.17, dsn=2.0.0, status=sent (delivered via myhook service)
May  1 18:39:35 Mailsrv1 postfix/pipe[16930]: 5073D39F00DE: to=<xxxxxxxxx@xxxxxxx.com.sa>, relay=myhook, delay=5.2, delays=5.1/0/0/0.17, dsn=2.0.0, status=sent (delivered via myhook service)
May  1 18:39:35 Mailsrv1 postfix/qmgr[14595]: 5073D39F00DE: removed



As we se here that the email will be relayed to myhook service which is the script that will check message date and change it. after that it will be send to port 10025 ( which we created to prevent loop). Also be informed that you can use any other content filter you want. 

Refrences

Tuesday, September 11, 2012

Sybase Backup Schedule



#!/bin/ksh
###############################Loading Sybase Enviroment variables
#
# Sybase Product Environment variables
#
SYBASE_ASE="ASE-15_0"
export SYBASE_ASE
PATH="/usr/sybase/ASE-15_0/bin:/usr/sybase/ASE-15_0/install":$PATH
export PATH
LD_LIBRARY_PATH="/usr/sybase/ASE-15_0/lib":$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
LD_LIBRARY_PATH_64="/usr/sybase/ASE-15_0/lib":$LD_LIBRARY_PATH_64
export LD_LIBRARY_PATH_64
SYBASE="/usr/sybase"
export SYBASE
SYBASE_OCS="OCS-15_0"
export SYBASE_OCS
PATH="/usr/sybase/OCS-15_0/bin":$PATH
export PATH
LD_LIBRARY_PATH="/usr/sybase/OCS-15_0/lib:/usr/sybase/OCS-15_0/lib3p64:/usr/sybase/OCS-15_0/lib3p":$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
INCLUDE="/usr/sybase/OCS-15_0/include":$INCLUDE
export INCLUDE
LIB="/usr/sybase/OCS-15_0/lib":$LIB
export LIB
LD_LIBRARY_PATH_64="/usr/sybase/OCS-15_0/lib:/usr/sybase/OCS-15_0/lib3p64:/usr/sybase/OCS-15_0/lib3p":$LD_LIBRARY_PATH_64
export LD_LIBRARY_PATH_64
SYBASE_JRE6_32="/usr/sybase/shared/JRE-6_0_6"
export SYBASE_JRE6_32
SYBASE_JRE6_64="/usr/sybase/shared/JRE-6_0_6"
export SYBASE_JRE6_64
SYBASE_JRE6="/usr/sybase/shared/JRE-6_0_6"
export SYBASE_JRE6
PATH="/usr/sybase/UAF-2_0/bin":$PATH
export PATH
SYBASE_UA="/usr/sybase/UAF-2_0"
export SYBASE_UA
SYBASE_PLATFORM="sunx"
export SYBASE_PLATFORM
PATH="/usr/sybase/DBISQL/bin":$PATH
export PATH
SCROOT="/usr/sybase/shared/sybcentral600"
export SCROOT
PATH="/usr/sybase/ASEP/bin":$PATH
export PATH
echo $sybaseTH="/usr/sybase/RPL-15_0/bin":$PATH
export PATH
SYBASE_WS="WS-15_0"
export SYBASE_WS
PATH="/usr/sybase/ASE-15_0/jobscheduler/bin":$PATH
export PATH
SYBROOT="/usr/sybase"
export SYBROOT
##################################


isql -Usa -Ppassword -Sservername  << EOF
print "Dumping db1 database"
print "--------------------------------------"
go

dump database databasename to '/usr/sybase/backup/databasedumpfile'  at backupservername_BS
go

Sunday, July 8, 2012

Caching dailymotion.com using SQUID

How to cache Dailymotion video using SQUID 

 You have to follow  the same way of caching youtube and other  videos
and add this line 

acl videocache_allow_url url_regex -i proxy[a-z0-9\-][a-z0-9][a-z0-9][a-z0-9]?\.dailymotion\.com\/video\/[a-z0-9]\/[a-z0-9]\/

reload your squid server and have fun

#tailf /var/log/squid/access 


192.168.1.55 - - [08/Jul/2012:09:14:13 +0200] "GET http://proxy-53.dailymotion.com/video/029/480/47084920_mp4_h264_aac_hq.flv? HTTP/1.1" 200 2176756 TCP_HIT:NONE