Sanjoy Roy

[MCM, MCP, SCJP] – Senior PHP Programmer

Category Archives: Linux Command

Copy recursively directory structure using Linux Command


How to copy a directory/folder structures in a single command
Create a new directory
Cd new_directory
Run the following command
Where “../catalog” is the source location
***Remember to backup before running this script.

e.g

find ../catalog -type d -printf “%P\n” | xargs mkdir -p

find ../admin -type d -printf “%P\n” | xargs mkdir -p

Advertisements

Some Linux useful IP commands


Display Current Config for all NIC’s: ifconfig

Display Current Config for eth0: ifconfig eth0

Assign IP: ifconfig eth0 192.168.1.2

Ping: ping -c 3 192.168.1.1

Assign multiple IP’s: ifconfig eth0:0 192.168.1.2

Assign second IP: ifconfig eth0:1 192.168.1.3

Disable network card: ifconfig eth0 down

Enable network card: ifconfig eth0 up

View current routing table: route “or” route -n

View arp cache: arp “or” arp -n

Assign IP/Subnet: ifconfig eth0 192.168.1.2 netmask 255.255.255.0

Assign Default Gateway: route add default gw 192.168.1.1

Trace Route: traceroute http://www.whatismyip.com

Trace Path: tracepath http://www.whatismyip.com

DNS Test: host http://www.whatismyip.com

Advanced DNS Test: dig http://www.whatismyip.com

Reverse Lookup: host 66.11.119.69

Advanced Reverse Lookup: dig -x 66.11.119.69

*You MUST be at the ROOT user to make/save any changes. Linux users, your distribution will determine the location of your network config file which will need to be updated and saved in order for the changes to remain in effect after rebooting. Network cards are referred to as eth0, eth1, eth2, etc based on their position on the PCI bus.
*Special thanks to Gergely for the Linux commands!

 

How to create a Password Protected Directory using linux command prompt?


Create a .htaccess file in the folder you want to set.
like:
#root@adu [/home/hostsite/public_html/admin]# vi .htaccess
copy and paste the following lines:
———————————————————-
AuthName “Secure Area”
AuthType Basic
AuthUserFile /home/hostsite/public_html/admin/.htpasswd
require valid-user
———————————————————-
Now set a password:
#htpasswd -c .htpasswd admin
New password: admin321
confirm password: admin321

You are done. test it: http://www.hostsite.com.au/admin and enter user name as admin and password as admin321

Cpanel Webalizer statistics without cpanel login


CPanel offers you the ability to check your website statistics with a program called webalizer. The problem with this system is that you are required to login via cpanel, and click through 2 diferent subsections in order to access them. This tutorial will guide you on the steps needed to make your webalizer statistics available via http://www.yoursite.com/stats/ .

Login to your hosting account via ssh. If you do not have ssh, ask your host to enable it. if they won’t enable it, ask them to read this tutorial, and run through these directions yourself.

Navigate to your public_html directory by running the following command

cd public_html

Once there, type the following:

vi .htaccess

once that loads, hit your i key, and type the following:

Options +FollowSymLinks

Once that is done, hit your Esc (escape) key, and type the following:

:wq

This will write to the .htaccess file, and quit.

Next, run the following command

ln -s ~/tmp/webalizer stats

you can replace the “stats” part of that command with name you want to use in order to access your website statistics.

After that, run the following commands

chmod 755 ~/tmp
chmod 755 ~/tmp/webalizer

now you can access http://www.yoursite.com/stats/ to access your webalizer statistics.

Enjoy

Plesk start-stop command

Linux command for Backup Script


You need to login to the shell and run following commands for both mysql databases and files.

e.g

tar -cvzf absblanksshirts.com.au.tar.gz httpdocs/
mysqldump -u absblank_ssitecms -p absblank_ssitecmsdb >absblanksshirts.sql

To view webalizer stats without login to cpanel


To view webalizer stats without login to cpanel do the following steps using shell :

1.First go to the public_html folder user :
# cd /home/username/public_html
e.g  cd /home/candylip/public_html/

2. Open .htaccess file. Add following code and save it:
Options +FollowSymLinks

You can edit the .htaccess file of the root store via vi editor.

3. Now create syblink for weblizer. Replace domainname.stats with name you want in order to access your website statistics. Change the owner to account user and permissions to 755.

#ln -s ../tmp/webalizer domainname.stats
chown username.username domainname.stats
chmod 755 ../tmp/webalizer

e.g:
#ln -s ../tmp/webalizer exclusiv.stats
#chown exclusiv.exclusiv exclusiv.stats
#chmod 755 ../tmp/webalizer

http://125.214.71.444/~exclusiv/exclusiv.stats

Unblocking IP address in Cpanel Server or Linux Command Line


You can unblock if from server shell console or from csf plugin if the serve is running cpanel.

For 125.214.71.115 in WHM under the Plugins section go to ConfigServer Security&Firewall.
Quick Allow tool should solve any blocking issues.

If the server is not running Cpane then from linux console run :
csf -a $IP
where $IP is IP you want to unblock and whitelist.

e.g:

root@secure [~]# csf -a 110.174.81.206
Removing 110.174.81.206 from csf.deny and iptables DROP…
DROP  all opt — in !lo out *  110.174.81.206  -> 0.0.0.0/0
DROP  all opt — in * out !lo  0.0.0.0/0  -> 110.174.81.206
Adding 110.174.81.206 to csf.allow and iptables ACCEPT…
ACCEPT  all opt — in !lo out *  110.174.81.206  -> 0.0.0.0/0
ACCEPT  all opt — in * out !lo  0.0.0.0/0  -> 110.174.81.206
root@secure [~]#

%d bloggers like this: