Hi Guys, We learn something new everyday. I did too. I know I am a late learner but its better late than never. I asked myself a question about how to write multiple lines using say echo to a file. I generally will open my vi editor and and write something there and then save my file. and when I am using echo I never really had that situation where I need to write multiple lines to a file. But things changed :) Normally I will do something like this Above will write word hello to file named test.txt in your current directory Let me show you how to write multiple lines Trick is when you start you echo command follow it with " (double quotes) and don't close them until you are finished with your sentense as shown below Above will write "Sit lectus dis placerat non aenean ultrices. Tempor, amet nisi in arcu, amet turpis, cras mattis ultrices, enim, penatibus. " to your test.txt file. I hope this helps Cheers … [Read more...]
.htaccess redirect all traffic to maintenance page except my IP address
Hi Guys, This is a follow up to my previous post. I had to switch one of my website off for general public viewing while I was doing some maintenance work. There are many reasons why you would like to do redirect all website visitors to your maintenance page. Few question that you may ask yourself are Do I want my site visitors to see 404, 403 (depending what you do), while I do my maintenance work Do I wish to update my users about how long still they will need to wait before they can order or get help from my website. Do I want them to feed them useful links from maintenance so that they can view your mirrored website etc etc For any of the above questions if you answered Yes to one of them read below else you can play another game of iBasket on your iPhone :) Ok So here is the deal Lets first redirect all traffic to your maintenance page Open your .htaccess file and paste the following In the above snippet just chage YOUR_MAINTENANCE_PAGE to a fitting name e.g. index_down.html or index_maintenance.html etc Let me try to explain above rule. Above rule says redirect all URLs that does not end with /YOUR_MAINTENANCE_PAGE.html to YOUR_MAINTENANCE_PAGE.html That's Ok if you are just uploading a couple of updates and but what if you are going to change your cart and you need some testing of you new stuff. You guessed it right, we will allow your IP normal access to the website. So change the above rule to this Make required changes IP address Maintenance file name to above Upload or save your .htaccess file and try to access you website from your home and office. Depending on which IP is allowed will see your website as per normal and other will be redirected to your maintenance page Pre-requites: You will need mod_rewrite module enabled in your apache web server for the above to work. So uncomment mod_rewrite line in your apache config, restart the … [Read more...]
.htaccess Block all IP but mine to access my website
Hi Guys, Well I am writing this one because I thought I did this stuff today so why not share :) Well sometimes when you are testing your application online, I mean your website you really don't want general public to get access to your website which is still under construction. Your use case scenario may differ but here is something that you can do really quick and easy using .htaccess file that is really a handy file and generally exists in your website root directory. You can do the same stuff that I am going to show you in actually httpd.conf or apache.conf files too. But lets see what needs to be done in case to achieve the above Simple enough, so we have set a rule for the current website that anyone other than YOUR _IP_ADDRESS should be denied access to your website. Remember to change YOUR_IP_ADDRESS to your own IP address such as 123.234.345.456 In other scenarios if you work from home and office then you will want to add more IP address to be able to access you website. Here is what you can do Simple so yeah you add more "allow from" lines to your .htaccess file. If you don't already have .htaccess file you will have to create one something like this assuming that your website root is /var/www/html In windows you can use your text editor to create one and then upload it to your website root directory. I hope this helps you Cheers … [Read more...]
linux list/find all files owned by a group or user
Hi Guys I thought I should share this one with you I had to audit my website files on Linux where I needed to see all files in a directory owned by user or group called apache. This is how I did it I used a Linux command (I should say a Language) called find I think this command can find caveman using iPhone :) You can find more about find command here http://linux.about.com/od/commands/l/blcmdl1_find.htm To make your task easier I'll highlight the important part that applies to heading Legend: IN_DIRECTORY : find command will work on this directory, so replace it by the directory name that you would like to search in -group { group-name} : Find file that belongs to group-name. -user {user-name} : Find file that is owned by user-name. Lets take a look at what I did As you see in the Image above I got file called crontab.bak and did a find with -user and -group. One thing to consider here is that when you use both switches together it makes it read as "find all files owned by -user AND -group". Below Screen grab clarifies it As you see above that I chown'ed crontab.bak file and make user web an owner of this file and when I try to run this command it gives me expected results. As you see that above works fine but the output is not really readable when search returns many files. Now what bob? Ok take a look at screengrab below and see what I did to beautify the output As you can see that I added a -ls switch and it beautifies my output. You have an option though to use -ls or -printf to format your output. I hope this helps … [Read more...]
centos-Red Hat disable selinux or set selinux off
Ok so I had this problem with SELinux so I wanted to turn it off I am not a pro Linux guy thats why I find SELinux very daunting to configure. Instead I just rely on Firewalls whenever I can. Said that this is not an advice. I use SELinux too but in some scenarios So let me show you how you can disable SELinux to off Let me tell you that by disabling SELinux you will be removing a security mechanism on your system set by default when you install your OS. Open your Shell and use these commands Below are the content of selinux config file # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=enforcing # SELINUXTYPE= can take one of these two values: # targeted - Only targeted network daemons are protected. # strict - Full SELinux protection. SELINUXTYPE=targeted Change SELINUX=enforcing to SELINUX=disabled and reboot your system Reboot is required to completely turn off Selinux … [Read more...]
How to: Finding particular text in Files or directory Linux
Well this is relatively simple. Linux comes with variety of utils that can be used to accomplish this task. Before I jump into this topic further I would like you guys have a look at this lovely book on Linux which covers many things. Alright Bob! Lets get started. In this tutorial I am going to use grep command. This command is really really fast to run. I could be wrong here because I am only an intermediate user of Linux and not an Expert :) To find specific text in a file use this command To find text in specific file extensions use this command To find in all files under a given directory To find in all files under a given directory and its subdirectories, we introduce -R (recursive switch) … [Read more...]
How to move or copy files of particular extension type from one directory to another directory in Linux?
Hi Guys, Its really simple to move files from one folder to another but what about some specific files with specific extension. I am sharing the solution that I came up with below. I also ask you to consider this lovely book on your right. This is common when you want to consolidate something under a directory. My use case was that I wanted to move all my .config files from /var/www/html/project folder to /var/www/html/config folder find command was my helper here. To find more about find command type To achieve this first I created a folder called config under project folder using this command. Then I used this command to move all my .config files from /var/www/html/project folder → /var/www/html/config folder How to read the above find command traverse the /var/www/html/project folder. Important bit is /* here which tells this command to read all files under project folder -name '*.config': find command will be looking for files whose name matches this pattern i.e. in our case ".config" files -exec mv -i {} -t /var/www/html/config \; -exec perform move command (mv) on each file, replacing {} by the path to the file collected from find command. As an exercise try this Note replace path-to-folder-a and path-to-folder-b to absolute path of you current working folder which you can get from "pwd" command. Here is a description of above steps Create directory a Change directory to a (not required but lets do it anyway) create a file called a.txt see if the file is there get out of a create directory b find all txt files in a move all text files from a to b change directory to b list all files (a.txt should now be there) The above will work the same way for copy command (cp) So for copying we will change the above command to I hope this helps … [Read more...]
how to kill a process in linux?
So you have a process running that took control of your system resources. hmm.. lets kill that process.. Generally a process loose its way because of loose pointers or a dependent resource is not responding or there can be any number of other reasons. I would generally shutdown the non responding process and start it again so that your system performance do no suffer. Linux comes with commands like kill, killall to kill the processes. I will recommend not using killall for a start. First up is that we would like to know which processes are running in our system, for that we will use ps command as shown below. Read more about this command here http://unixhelp.ed.ac.uk/CGI/man-cgi?ps This will list all the processes running on our system. but say the troubled process is a php script that is stuck in its for loop. I will thus pipe the output of ps command to grep command to find the process ID of this phpscript The above command will produce an output shown below (example) We can also utilize a command called pidof as shown below The problem with above command is that we can not pin point which php script we need to kill. but for killing processes such as httpd, mysql etc its ok to rely on the output of the above command. now that we got hold of the process that we need to kill that is 14540 we run the command below to kill it. Read more about kill command here http://unixhelp.ed.ac.uk/CGI/man-cgi?kill The command kill sends the specified signal to the specified process or process group. If no signal is specified, the TERM signal is sent. The TERM signal will kill processes which do not catch this signal. For other processes, it may be necessary to use the KILL (9) signal, since this signal cannot be caught. as per the command definition above you may need to use -9 switch to force kill the process as shown below killall on the other hand kills processes by their name, so to kill a process called … [Read more...]
finding an IP in apache access logs and number of times it is repeated
So I got this problem today so while I wrote a single like command just to achieve that I would like to share as well. Lets discuss the problem first: I have to find an I.P. address from the access logs and check the number of times it gets repeated I assume that you are already in the directory where you access logs are. This technique applies to any file type as long as its readable. I started with this command the above command gives me all lines in my access log where this I.P. address is present. now I will just need to count the number of lines returned which is really simple as shown below I've created a pipe and fed the result of grep command to wc command (wc -l will count lines) you can also write a small script where you can feed all the access log files one by one to the above command and recording the results to analyze afterwards. My access log file names are dates so for me it is easier say for example to find this I.P. by date and say if this I.P. ever visited on a certain date. You can however do this sort thing in several ways anyway. I hope this helps. … [Read more...]




Recent Comments