Thursday 14 May 2015

Deleting all large size files from all directories using Bash in Linux

If you are looking to delete all the files in Linux Web Server by specifing File Name and File Size,
then follow steps below:

1. Login into your server Terminal via root login.
2. Create a new bash file called clean_up.sh in one of the location
e.g. /home/my_script/

3. Then Copy and the below code and Paste into that file and Save it.
clear
echo ' -------------------------------------------------------------------------'
echo '  Cleaning all large size error_log files from all directories.'
echo ' -------------------------------------------------------------------------'

filename="error_log"
filesize="50000"

echo " Deleting all files (including subfolders) having Filename:'$filename', Size: greater than $filesize Kb only."
echo ' '
echo ' Listing all the files which are greater than 50MB'
find / -type f -size +50M -exec du -h {} \; | sort -n

echo ' Deleting all the "error_log" files which are greater than 50MB'
#find -name "error_log" -size +30000k #-delete
find -name "$filename" -size +"$filesize"k -delete

echo ' Listing again all the files which are greater than 50MB'
find / -type f -size +50M -exec du -h {} \; | sort -n

4. Then go to your specified directory where you want to Search and Delete the files by specifying the File Name and File Size as below;

5. Then run the below command
sh  /home/my_script/clean_up.sh

Tuesday 12 May 2015

To change the default port 8069 to 80 or any other port in Odoo/OpenERP 8+

Whilst installing Odoo/OpenERP into your local server, please download directly from Odoo website.

PS: please do not use Bitnami Odoo version as its bit outdated (unless they have released the latest Odoo updated version for 8.0+). You may use install it from them but it runs very slowly and takes a lot of memory than the version directly from Odoo.

Once you have downloaded the latest Odoo 8.0 plus directly from Odoo website, just run the .exe file.

By default, it runs under the 8069 port number. However, you can change to any other port as you like, for eg. to port 80.
  • First, copy a the root/server/openerp-server.conf file into the desktop and open it on editor, goto Line number => 60 (root/ folder is a location where Odoo has been installed).

    Modify the Line number => 60 from xmlrpc_port = 8069 to xmlrpc_port = 80 (or any other numer as you required) and save a file. 

  • Then COPY that file from destktop and PASTE it into the root/server/ location.
  • Secondly, copy a the root/server/openerp/tools/config.py file into the desktop and open it on editor, goto Line number => 155 (root/ folder is a location where Odoo has been installed).

    Modify the Line number => 155 from my_default=8069, to my_default = 80 (or any other numer as required) and save a file. 

  • Then COPY that file from destktop and PASTE it into the root/server/openerp/tools/ location. 
  • Lastly, RESTART the machine and it should work.

Please comment here if you have further information or if you have any issue.

Hope that helps!

Tuesday 5 May 2015

Print the HTML contents via Element Id or Class Name via Javascript/jQuery

Please use the below function to print the HTML contents via Element Id or Class Name via Javascript/jQuery.
PS: You would require jQuery library to link.
/* 
* Function to print the HTML contents via element Id or Class 
* elem This can be Name of the tag ID or Class 
*/
function PrintMe(elem) {
 
 var pageHeaderTitle = 'Enter you Page Header Title here';
 var bodyTitle = 'Enter you Page Title here';  
 var bodySubTitle = 'Enter you Page Sub Title here'; // (optional) 
 var pageData = jQuery(elem).html();
 
 var siteLogoCaption = 'Your Site Name';
 var site_logo_alt = '/images/logo/logo.jpg';
 
 var css_bootstrap_file_url = 'http://www.yourdomain.com/css/bootstrap.min.css';
 var css_custom_file_url = 'http://www.yourdomain.com/css/custom.css';
 
 var mywindow = window.open('', 'my div', 'height=600,width=800,scrollbars=yes');
 mywindow.document.write('< html>' + pageHeaderTitle + ' - <?php echo $site_name; ?>');
 mywindow.document.write('< link href="' + css_bootstrap_file_url + '" rel="stylesheet" type="text/css">');
 mywindow.document.write('< link href="' + css_custom_file_url + '" rel="stylesheet" type="text/css">');
 mywindow.document.write('< img alt="' + siteLogoCaption + '" height="auto" src="' + site_logo_url + '" style="float: left; margin-left: 40px;" width="100" />');
 mywindow.document.write('< div class="container" id="print_form" >< h3>'+ bodyTitle +'< /h3>');
 mywindow.document.write('< h4>' + bodySubTitle + '< /h4>< hr />');
 mywindow.document.write(pageData);
 mywindow.document.write('< p>---< /p>');
 mywindow.document.write('< /div>< /body>< /head>< /html>');
 mywindow.print();
 mywindow.document.close();
}

/** Invoking the printing function **/
< button class="btn btn-primary" onclick="PrintMe('#divContainerToPrint'); return false;" >Print< /button>