EZ Linux Admin random header image

How to search a directory for a certain search string.

January 23rd, 2012 by EZ linux · No Comments

Pretty simple, this takes minimal load and delivers the data as it’s found.

→ No Comments Tags: Linux Commands · Linux Software / Scripts · Linux Tricks


add a 404 page to each website on a cpanel server

December 28th, 2011 by EZ linux · No Comments

#!/usr/bin/perl
# cPlicensing.net – scripts            Copyright(c) 2003 cPlicensing.net.
#                                     All rights Reserved.
# support@cPlicensing.net              http://cPlicensing.net
# Version: 0.02

print “Starting Scan…\n”;

while(@USERS=getpwent()){
if (-d “$USERS[7]/public_html”) {
if (-f “$USERS[7]/public_html/404.shtml”) {
print “$USERS[0] 404.shtml exists\n”;
} else {
print “$USERS[0] creating 404.shtml…”;
open(FILE,”>$USERS[7]/public_html/404.shtml”) or die “Unable to create file: $!”;
close(FILE);
chmod(0644, “$USERS[7]/public_html/404.shtml”) or die “Unable to chmod file: $!”;
chown($USERS[2],$USERS[3],”$USERS[7]/public_html/404.shtml”) or die “Unable to chown file: $!”;
print “done\n”;
}
}
}
if (-f “/root/cpanel3-skel/public_html/404.shtml”) {
print “404.shtml file exists in skel dir\n”;
} else {
print “Creating 404.shtml file in skel dir…”;
open(FILE,”>/root/cpanel3-skel/public_html/404.shtml”) or die “Unable to create file: $!”;
print “done\n”;
}

print “Scan Complete!\n”;

#ChangeLog
#Version :: YYYY.MM.DD :: Type :: Description
#
#0.2 :: 2003.11.06 :: Bug Fix :: 404.shtml was created in the root skel folder, changed to public_html

→ No Comments Tags: Cpanel and WHM · Linux Security · Linux Software / Scripts


Backup cleaner script for cpanel

December 28th, 2011 by EZ linux · No Comments

#!/usr/bin/perl
# cPlicensing.net – scripts             Copyright(c) 2003 cPlicensing.net.
#                                       All rights Reserved.
# support@cPlicensing.net               http://cPlicensing.net
# Unauthorized copying is prohibited
#Version: 0.01

use POSIX;

$delete_old     = ’1′; #0 or 1, set to 1 to remove old account backups
if($ARGV[0] eq “-d”) { $delete_old = ’1′; }

$|++;
POSIX::nice(19);

print “Reading Backup Config…”;
open(CPBACK,”/etc/cpbackup.conf”) or die(“Failed, Does it exist and do you have access?\n”);
while(<CPBACK>) {
s/\n//g;
my($name,$value) = split(/ /, $_);
$CONF{$name} = $value;
}
close(CPBACK);
print “Complete\n”;

if ($CONF{‘BACKUPENABLE’} ne “yes”) {
die “Backup Not Enabled\n”;
}
if (! -e $CONF{‘BACKUPDIR’}){
die “Backup Dir Doesnt Exist\n”;
}

until (`ps ax` !~ m/cpbackup/) {
print “Detected cpbackup process…Sleeping for 60 Seconds\n”;
sleep(60);
};

if ($CONF{‘BACKUPMOUNT’} eq “yes”) {
if(`mount` !~ m/$CONF{‘BACKUPDIR’}/){
system(“mount”,”$CONF{‘BACKUPDIR’}”);
}
system(“mount”,”-o”,”remount,rw”,”$CONF{‘BACKUPDIR’}”);
}

cleandir(“$CONF{‘BACKUPDIR’}/cpbackup/daily”);
cleandir(“$CONF{‘BACKUPDIR’}/cpbackup/weekly”);
cleandir(“$CONF{‘BACKUPDIR’}/cpbackup/monthly”);

if ($CONF{‘BACKUPMOUNT’} eq “yes”) { system(“umount”,”$CONF{‘BACKUPDIR’}”); }

sub cleandir {
my($target) = @_;

opendir(DIRTYDIR,”$target”);
@DIRTYDIR = readdir(DIRTYDIR);
closedir(DIRTYDIR);

foreach(@DIRTYDIR) {
next if /^\.\.?$|^files$|^dirs$/;
if(-f “$target/$_”){
$user = $_;
$user =~ s/.tar.gz//;
if(! -f “/var/cpanel/users/$user”){
if($delete_old == 1){
unlink(“$target/$_”);
print “Deleted Old Backup… $target/$_\n”;
} else {
print “Detected Old Backup… $target/$_\n”;
}
}
next;
}
if(-d “$target/$_”){
if(! -f “/var/cpanel/users/$_”){
if($delete_old == 1){
system(“rm”,”-r”,”$target/$_”);
#print “Directory Delete Not Supported, If you really want to remove dirs (incremental backups) you can edit this script and uncomment the line that looks like #system(\”rm\”,\”-r\”,\”$target/$_\”)\n”;
} else {
print “Detected Old Backup… $target/$_\n”;
}
}
next;
}
}
}

→ No Comments Tags: Cpanel and WHM · Linux Security · Linux Software / Scripts


Manually changing an IP in Linux

December 17th, 2011 by EZ linux · No Comments

It’s pretty easy actually.

Just go to this directory:

/etc/sysconfig/network-scripts

Then you will see a file for eachnetwork port, for example my server is:

ifcfg-eth0

and

ifcfg-eth1

I already have the ifcfg-eth0 set up from the install but I want to use the second one for back ups so I just opened the file and added the IP to it. Then I made sure the rest of the setting smatched the first one other then the:

HWADDR=

That line is specific to the network port.

So that is how you configure a eth0 or eth1 port.

 

→ No Comments Tags: Cpanel and WHM · Hardware · Linux Drivers · Linux Operating Systems · Linux Security · Linux Software / Scripts · Linux Tricks · Ports


The skinny on raid differances

November 28th, 2011 by EZ linux · No Comments

We refer raid 5 but if you have remote back ups on the server then  raid 0 will get you the best performance between several hard drives. Keep in mind raid still can fail even with the same data going to several hard drives and this will slow your system down.

Hardware raid is much faster as it doesn’t steal ram and cpu to be used.

Software should be avoided like the plague it will cause load issues 90% of the time.

A number of standard schemes have evolved which are referred to as levels. There were five RAID levels originally conceived, but many more variations have evolved, notably several nested levels and many non-standard levels (mostly proprietary). RAID levels and their associated data formats are standardised by SNIA in the Common RAID Disk Drive Format (DDF) standard.

Following is a brief textual summary of the most commonly used RAID levels.

RAID 0 (block-level striping without parity or mirroring) has no (or zero) redundancy. It provides improved performance and additional storage but no fault tolerance. Hence simple stripe sets are normally referred to as RAID 0. Any drive failure destroys the array, and the likelihood of failure increases with more drives in the array (at a minimum, catastrophic data loss is almost twice as likely compared to single drives without RAID). A single drive failure destroys the entire array because when data is written to a RAID 0 volume, the data is broken into fragments called blocks. The number of blocks is dictated by the stripe size, which is a configuration parameter of the array. The blocks are written to their respective drives simultaneously on the same sector. This allows smaller sections of the entire chunk of data to be read off the drive in parallel, increasing bandwidth. RAID 0 does not implement error checking, so any error is uncorrectable. More drives in the array means higher bandwidth, but greater risk of data loss.

In RAID 1 (mirroring without parity or striping), data is written identically to multiple drives, thereby producing a “mirrored set”; at least 2 drives are required to constitute such an array. While more constituent drives may be employed, many implementations deal with a maximum of only 2; of course, it might be possible to use such a limited level 1 RAID itself as a constituent of a level 1 RAID, effectively masking the limitation.[citation needed] The array continues to operate as long as at least one drive is functioning. With appropriate operating system support, there can be increased read performance, and only a minimal write performance reduction; implementing RAID 1 with a separate controller for each drive in order to perform simultaneous reads (and writes) is sometimes called multiplexing (or duplexing when there are only 2 drives).

In RAID 2 (bit-level striping with dedicated Hamming-code parity), all disk spindle rotation is synchronized, and data is striped such that each sequential bit is on a different drive. Hamming-code parity is calculated across corresponding bits and stored on at least one parity drive.

In RAID 3 (byte-level striping with dedicated parity), all disk spindle rotation is synchronized, and data is striped so each sequential byte is on a different drive. Parity is calculated across corresponding bytes and stored on a dedicated parity drive.

RAID 4 (block-level striping with dedicated parity) is identical to RAID 5 (see below), but confines all parity data to a single drive. In this setup, files may be distributed between multiple drives. Each drive operates independently, allowing I/O requests to be performed in parallel. However, the use of a dedicated parity drive could create a performance bottleneck; because the parity data must be written to a single, dedicated parity drive for each block of non-parity data, the overall write performance may depend a great deal on the performance of this parity drive.

RAID 5 (block-level striping with distributed parity) distributes parity along with the data and requires all drives but one to be present to operate; the array is not destroyed by a single drive failure. Upon drive failure, any subsequent reads can be calculated from the distributed parity such that the drive failure is masked from the end user. However, a single drive failure results in reduced performance of the entire array until the failed drive has been replaced and the associated data rebuilt. Additionally, there is the potentially disastrous RAID 5 write hole.

RAID 6 (block-level striping with double distributed parity) provides fault tolerance of two drive failures; the array continues to operate with up to two failed drives. This makes larger RAID groups more practical, especially for high-availability systems. This becomes increasingly important as large-capacity drives lengthen the time needed to recover from the failure of a single drive. Single-parity RAID levels are as vulnerable to data loss as a RAID 0 array until the failed drive is replaced and its data rebuilt; the larger the drive, the longer the rebuild takes. Double parity gives additional time to rebuild the array without the data being at risk if a single additional drive fails before the rebuild is complete.

→ No Comments Tags: Hardware · Linux Back Up · Linux Security


Tracking down the biggest folders

August 11th, 2011 by EZ linux · No Comments

du -ax --max-depth 1 /var/cpanel | sort -n | tail

This is a great command to simply find what folders are the biggest in a directory. You can replace the /var/cpanel with any folder and it will list everything in there and how big they are in order.

Once you find the big folder then search inside of that to find the biggest folder in there and so on.

→ No Comments Tags: Cheat Sheets · Cpanel and WHM · Linux Commands · Linux Security · Linux Software / Scripts · Linux Tricks


Cleaning up /var

August 11th, 2011 by EZ linux · No Comments

Cpanel and linux leaves a lot of log files in /var
After several years these can add up, especially in the cpanel/bandwidth folder. So a couple quick folder moves and symlinks can clean things up. This is assuming you have a /backup partition and some room in it.

Moving the log folder

mv /var/log /backup/
ln -s /backup/log /var/log

Moving the cpanel bandwidth folder

mv /var/cpanel/bandwidth /backup/
ln -s /backup/bandwidth /var/cpanel/bandwidth

Also just removing some of the log files in the log folder can help you for a quick fix.

→ No Comments Tags: Cheat Sheets · Cpanel and WHM · Linux Operating Systems · Linux Security · Linux Software / Scripts · Linux Tricks


Clearing Your DNS Cache

July 19th, 2011 by EZ linux · No Comments

Clearing Your DNS Cache

Your DNS cache stores the locations (IP addresses) of pages you have recently viewed. If the location of the page changes before the entry in your DNS cache is updated, you will be unable to access the page.

If you are encountering a high number of HTML 404 error codes, you may need to flush your DNS cache. Once you clear your DNS cache, your computer will query nameservers for the new DNS information you require.

For more information about the HTML 404 error code, please visit the HTML 404 wikipedia article.

The methods detailed below allow you to remove old and inaccurate DNS information that may result in 404 errors.

Windows® XP, 2000, or Vista®

Open the Start menu.
Go to Run.
If you do not see the Run command in Vista, search for “run” in the Search bar.
In the Run text box, type: ipconfig /flushdns
Press Enter or Return, and your cache will be flushed.

MacOS®

Go to Applications.
Go to Utilities.
Open the Terminal application.
Type: dscacheutil -flushcache
Press Enter or Return, and your cache will be flushed.

→ No Comments Tags: Cheat Sheets · Cpanel and WHM


Remove Fantastico

June 26th, 2011 by EZ linux · No Comments

This short post is a response to the question I received from one reader that wanted to know how to remove completely from his Cpanel server Fantastico.
Why would you want to do that? (assuming you have it already installed, it means you have a license also). Well, maybe the data center installed it by default and you don’t need Fantastico on your server; or maybe you just have a broken install and want to start fresh and remove it first. Regardless why you would want to do this, here are the steps you need to follow to completely remove Fantastico:

Login your server via SSH as root, and run the following commands:
rm -rf /var/netenberg/
rm -rf /usr/local/cpanel/whostmgr/docroot/cgi/fantastico/
rm -rf /usr/local/cpanel/3rdparty/fantastico*
rm -rf /usr/local/cpanel/base/frontend/*/fantastico
rm -f /usr/local/cpanel/base/frontend/x/cells/fantastico.html
rm -f /usr/local/cpanel/whostmgr/docroot/cgi/addon_fantastico.cgi

Note: if you have installed fantastico in a different location than the default folder: /var/netenberg/, then you should replace the first line accordingly (this might be /opt/netenberg/, or /home/netenberg/, etc.).

→ No Comments Tags: Cpanel and WHM · Linux Software / Scripts


Change third party icon names in CPanel

June 23rd, 2011 by EZ linux · No Comments

Third party scripts like rv site builder, fantastico, and softaculous, have names that might confuse users. We found it better to change the names of these icons to what they are not the business names.

You do that in this folder:

/usr/local/cpanel/base/frontend/x3/dynamicui

Then changing the permissions to read only is a good idea in case the script tries to change it with a update.

 

→ No Comments Tags: Cpanel and WHM