Category Archives: Programming

Protect a location from Apache

Sometimes, you need to protect a certain location with Http Access and users must enter username and password to view that location. A simple way to do this is from Apache configuration file or from .htaccess <Location /my_location> AllowOverride AuthConfig AuthName “Please login!” AuthType Basic AuthUserFile /passwd/.htpasswd require valid-user <LIMIT GET> require my_user </LIMIT> </Location>… Read More »

Search text inside a file recursively

When you need to search recursively inside a structure of directories you need to run the following command from the console: find /srv -type f -follow -exec grep –with-filename –line-number “apache2ctl” {} ; This will search in every file from every folder from /srv and will show in which file and at each line it… Read More »

Start Apache & MySQL when your Linux starts

If you want to set what programs will start when you boot your Linux machine you must set the Run Levels. A visual way to do this, from OpenSuse 11.0 is: Yast -> System -> System Services (Run Level) -> Expert Mode After this you must enable those services. Cheers,

Send Error 404 Page not found from Apache

If you want to set an error page which will be shown everytime a user tries to access something that isn’t on your server, the best way to do this is from Apache configuration. All you have to do is to insert the following line into httpd.conf or other configuration file. ErrorDocument 404 http://domain.com/404_friendly_error_page.htm Cheers,

Make incremental backups with tar

Sometime, you modify a small file and you don’t need a full backup. It is recommended to make a full back-up every week and make everyday an incremental back-up. You can use tar to make incremental back-up. In the next example we will backup all files from /home/adrian that are modified in the last 2… Read More »

Find the date of a file with Perl

I need to do an incremental download and I need to know the date of the previews file. I found an interesting function in Perl: my $date = localtime( (stat HANDLE)[9] );

Bash current folder

Sometimes, if you run some bash scripts from cronjob or with the absolute path you will receive an error like this: Can’t open perl script “backup.cgi”. No such file or directory. To solve this, you must make sure you set bash to read from the directory where it is located: cd $(dirname $0) This will… Read More »