Showing posts with label tricks. Show all posts
Showing posts with label tricks. Show all posts

Thursday, October 31, 2019

Find and clear log files in Linux

Objective:

Find and clear the files with extension of *.log, usually log files.

Commands:

find . -type f -iname *.log -exec tee {} \; </dev/null

This command will find the files with extension of 'log' and empty that file. Which means file will be there and data of that file will be cleared.

If you are using cPanel, there will be a directory called "virtfs", in that case you can use following command.

find /home -type f -iname *.log -not -path "./virtfs/*" -exec tee {} \; </dev/null

Please note, in WHM / cPanel server, this will clear logs including created by server.

So, If you need to do this manually for specific file, you can simply use any of following commands,

# > file.name

# :> file.name

# true > file.name

# echo "" > file.name

# echo  > file.name

# dd if=/dev/null of=logfile

# dd if=/dev/null > logfile

Still there are several methods to clear it.

Saturday, July 21, 2018

Finding multiple folders in Linux with single command

Finding multiple folders with single commend on Linux is not a big deal.

I wanna know all temp / tmp and cache folders in websites, that are configured with WHM to exclude from the backup. Here is the command for that,


find /home/*/public_html \( -type d -iname "cache" -or -iname "tmp" -or -iname "temp" \)

To know size of these folders,

find /home/*/public_html \( -type d -iname "cache" -or -iname "tmp" -or -iname "temp" \) -exec du -sh {} \;

Thursday, February 23, 2017

Increase WordPress URL Length

Hello Guys,

I'm back here after a long period. Today I would like to share the simple trick for WordPress Blogging. If you need to increase URL length in wordpress sites, do following things.

1. On page "wp-includes/formatting.php" find the following line and change the value that mention as Bold

function sanitize_title_with_dashes

$title = utf8_uri_encode($title, 300);

2. In database, find the table and change the value of table field.
wp_post => post_name => varchar 300


============================

Drawback of this setup

Whenever WordPress release update and you update your website, the default setting will be over write.

But, It won't affect the custom URL that you have assigned to the post. So that old URLs may not work until you do the same URL length increasing process.

Thursday, June 18, 2015

Clearing RAM cache and SWAP memory in Linux

If your server get hanged, RAM cache is one of the major reason,. It happens frequently on web server when we are under attack or web developer dosen't consider about performance of application. Miss configuration of servers like mysql and apache is one of the main reason.

We can see ram cache amount on htop, which is user friendly monitoring tool for Linux servers. Because of it we may loss some connections and it's interaction with server. We can do this by our own risk.

What is RAM cache ?

It is a portion of memory made of high-speed static RAM (SRAM) instead of the slower and cheaper dynamic RAM (DRAM) used for main memory. Memory caching is effective because most programs access the same data or instructions over and over.

To clear cache :

free -m && sync && echo 3 > /proc/sys/vm/drop_caches && free -m

To clear pagecache change value of echo to 1 on about commend, to clear dentries and inodes change value of echo to 2 on about commend, echo 3 will clear all of three pagecache, dentries and inodes.

To clear swap:

Up-to I know that there is no straight way to this, But we can do it by disable and enable the swap, We can do this by following command,

To turn off : swapoff -a
To turn on : swapon -a 

Wednesday, May 6, 2015

Finding malware codes on web pages

It is beginners trick, not advised for administrators.

Lot's of tools are available on Linux to find the malware codes injected on server. But most of them not detect the page with url encoded. Because it's php functionality. Mostly of this happens when developer or administrator not aware problem when we providing 777 permissions to pages on web servers. In these cases simple java-script injection will make server to get down.

We can disable this function, urldecode but unfortunately it's bad idea on shared hosting and most of frameworks using url encode and decode. In this case, we can do some manual work for figure-out codes by following commend.

find . -iname '*php' | xargs grep 'urldecode' -sl

This will list the files that have urldecode. We can check page and remove code.

Tuesday, February 3, 2015

Query to find size of MySQL DB

When we are using shared hosting server with Windows or Linux, without any control panel software, It's little bit hard to find user's disk usage on mysql.

In this case we can use  following command on mysql to get size of database.

SELECT table_schema "DB Name", Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" FROM information_schema.tables GROUP  BY table_schema;

Tuesday, October 21, 2014

Disabling local mail for a domain on parallel plesk panel

When we migrate mail servers with parallel plesk panel, We can use plesk migration manager.

But some case, we migrate server manualy,

Last time I faced following issue,

Server 1 : Current server
Server 2 : New Server

We had around 50 domain / subscription in our server. We planned to switch Server 1 to Server 2 one by one.

By commands & scripts, we've created all domains and mail accounts to Server 2. But we didn't change all domain MX to server 2. That means first 20 domains run in Server 2 and another 30 domains in Server 1.

In this case we got issue for deliver emails from Server 1 to Server 2 and vise-versa.

In this case problem with resolving domain

Any mail server first try to check whether domain in local server or not. If it in local server, it'll deliver mail to mail box directly. In our case both server have all 50 domains and their mail box. So it trying to deliver mails with in server. So it not reach to real location of mail box.

Solution !!! It's not a good idea to remove domains and mail account which is not usable. I've tried with disabling mail box in plesk panel. No use of it. Because it'll just stop sending mail to mail box. But local domain resolvation  won't be stop.

So I've to stop mail service for that domain, following command helped to do that.

/usr/local/psa/bin/mail --off domain.com

If you want to enable domain again, use following command

/usr/local/psa/bin/mail --on domain.com



Force Qmail to process all mails in the queue

Some times qmail not deliver mails, due to connection issue, in that case we can force qmail to send mails forcefully with following command.

This will send alarm signal to mail send.


 kill -ALRM `ps ax | grep [q]mail-send | awk '{print $1}'`


Source : Plesk support

Monday, October 20, 2014

Changing mail queue life time in qmail installed with plesk

Default queue life time is 7 days. That means, your mails will be stored in queue for 7 days if it not able to deliver. 

We can reduce this queue time with following steps.

To check current queue life time:

/var/qmail/bin/qmail-showctl | grep life

Time mentioned as seconds,


To set queue life time:

echo "172800" > /var/qmail/control/queuelifetime

Here I've set queuelifetime is 2 days.


For changes to take effect

service qmail restart

or

/etc/init.d/qmail restart

Monday, June 10, 2013

Adobe Flash Player Standalone Offline Full Installer for Windows


Good thing in these links are up to date automatically by Adobe. 
So no need to bother about whether it's updated or not.

Internet Explorer

All other browsers Firefox, Chrome etc.

Tuesday, February 21, 2012

SAMBA client in Linux with GUI

We can connect samba server with GUI mode as like windows machine in Linux.

Run Application will be used to access samba server in Linux with GUI.

Alt+F2 used to open Run Application window.

It looks as follows.

run application

Just type smb://{samba server address} and hit Enter.

Ex.

smb://10.1.1.1

This will open your samba share window. Give password if it asks.

Monday, January 30, 2012

Play NFS (Need For Speed) or other Games on Full Screen in Laptop with Windows 7

Now a days most of people playing NFS serious (NFS Most Wanted , NFS Carbon etc.) in Laptop.

We are facing the problem that NFS game does not play in full screen mode. It have some black bar at both right and left side.

We can fix it with simple steps, For this your video driver should be installed with it's "Graphics & Media Control Panel" application.

Here i have explained it with screen shot. It'll be mostly same for Intel boards. Settings for other video drivers may differ. You may need to search for it in their graphics control panel.


Step 1 :

Click aero button at right bottom corner for show available notifications and running process. There is Graphics & Media Control Panel Icon.
If it is not avaliable there, you can get it from "Windows Control Panel".
It'll open your "Graphics & Media Control Panel".
 


Step 2 :

Click Graphics & Media Control Panel icon and choose Graphics Properties...


Step 3:

Under Intel Graphics and Media Control Panel,
Display -> General Settings -> Scaling -> Scale Full Screen


That all, Then apply and ok.

Here after your can play any of your favourite game as full screen in your Laptop and Desktop.

Saturday, June 11, 2011

Windows XP Hidden apps

Following comments are execute throw run command box,

  1. Character Map = charmap.exe (Useful for finding characters)
  2. Disk Cleanup = cleanmgr.exe (Clean temp / compressed files)
  3. Clipboard Viewer = clipbrd.exe (Views contents of clipboard)
  4. Dr Watson = drwtsn32.exe (Troubleshooting tool for windows xp)
  5. DirectX diagnosis = dxdiag.exe (Diagnose & test DirectX, video & sound cards)
  6. Private character editor = eudcedit.exe (allows creation or modification of characters)
  7. IExpress Wizard = iexpress.exe (Create the self-extracting / self-installing packages for windows)
  8. Microsoft Synchronization Manager = mobsync.exe (appears to allow synchronization of files on the network for when working offline. Apparently undocumented)
  9. Windows Media Player 5.1 = mplay32.exe (Retro version of Media Player)
  10. ODBC Data Source Administrator = odbcad32.exe (Database connectivity)
  11. Object Packager = packager.exe (to do with packaging objects for insertion in files, appears to have comprehensive help files)
  12. System Monitor = perfmon.exe (To know about PC performance)
  13. Program Manager = progman.exe (Legacy windows 3.x desktop shell) // didn't work for me.
  14. Remote Access phone book = rasphone.exe (documentation is virtually non-existant)
  15. Registry Editor = regedt32.exe or regedit.exe (For edit windows registry)
  16. Network shared folder wizard = shrpubw.exe (creates shared folders on network)
  17. File siganture verification tool = sigverif.exe
  18. Volume Control = sndvol32.exe
  19. System Configuration Editor = sysedit.exe (for edit System.ini & Win.ini)
  20. Syskey = syskey.exe (Secures XP Account database - use with care, it's virtually undocumented but it appears to encrypt all passwords)
  21. Microsoft Telnet Client = telnet.exe
  22. Driver Verifier Manager = verifier.exe (Utility for monitoring the actions of drivers)
  23. windows for Workgroups Chat = winchat.exe (chat sessions over a LAN)
  24. System configuration = msconfig.exe (can use to control starup programs)
  25. gpedit.msc used to manage group policies, and permissions..!