Click Technology

Linux, Windows, Mac it's all good

Rotate logs

September13

Sometimes you will need to force logs to be rotated. No problem. This can be done manually. Here’s the command.

logrotate -v -f /etc/logrotate.d/rsyslog

This will compress and rotate all the significant logs.

To check which logs your machine will rotate, examine the file /etc/logrotate.d/rsyslog

/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages

Done.

posted under Linux Tips | No Comments »

Set up CodeIgniter quickly…

September12

The CodeIgniter framework is great, even the documentation is spot on being short and to-the-point.

They have installation instructions, sure, but here’s the commands to download it and set it up with the folders in the correct place.

First step, log into your server over SSH. I assume you are using Apache in this process for the web configuration, and that your root folder for serving web files is /var/www as is typical.

If you’re using nginx or something else, server side config is still straightforward, just a question of setting your document root AFAICS.

Here’s the steps..

This will download the CodeIgniter yip, unpack it, set it up, add a .htaccess file, set up the database connection and make you feel good about yourself generally. Use with the ususal care and attention.

cd /var/www
sudo rm -rf /var/www/yourwebsite.com
sudo mkdir /var/www/yourwebsite.com
cd /var/www/yourwebsite.com
sudo wget https://ellislab.com/codeigniter/download --output-document=./CodeIgniter_2.2.0.zip
sudo unzip CodeIgniter_2.2.0.zip
sudo rm CodeIgniter_2.2.0.zip
sudo mv ./CodeIgniter_2.2.0 ./public_html
sudo mv ./public_html/system/ ./
sudo mv ./public_html/application ./
sudo sed -i s/"$system_path = 'system';"/" = '\/var\/www\/yourwebsite.com\/system';"/g ./public_html/index.php
sudo sed -i s/"$system_path = 'application';"/" = '\/var\/www\/yourwebsite.com\/application';"/g ./public_html/index.php
sudo su -c $'echo "RewriteEngine on" >> /var/www/yourwebsite.com/public_html/.htaccess'
sudo su -c $'echo "RewriteCond \$1 !^(index\.php|images|robots\.txt)" >> /var/www/yourwebsite.com/public_html/.htaccess'
sudo su -c $'echo "RewriteRule ^(.*)$ /index.php/\$1 [L]" >> /var/www/yourwebsite.com/public_html/.htaccess'
sudo sed -i s/"\$autoload\['libraries'\] = array('');"/"\$autoload\['libraries'\] = array('database');"/g /var/www/yourwebsite.com/application/config/autoload.php
sudo sed -i s/"\$db\['default'\]\['username'\] = '';"/"\$db\['default'\]\['username'\] = 'your_database_username_for_your_codeigniter_app';"/g /var/www/yourwebsite.com/application/config/database.php
sudo sed -i s/"\$db\['default'\]\['password'\] = '';"/"\$db\['default'\]\['password'\] = 'your_database_password_for_username_above';"/g /var/www/yourwebsite.com/application/config/database.php
sudo sed -i s/"\$db\['default'\]\['database'\] = '';"/"\$db\['default'\]\['database'\] = 'my_codeigniter_app_database';"/g /var/www/yourwebsite.com/application/config/database.php
sudo su -c $'chown -R www-data:www-data /var/www/yourwebsite.com'
sudo su -c $'find /var/www/yourwebsite.com -type f -print0 | xargs -0 chmod 0664'
sudo su -c $'find /var/www/yourwebsite.com -type d -print0 | xargs -0 chmod 0775'
sudo su -c $'service apache2 restart'

OK, that’s it. Start working on the app. The part below was a step by step for the apache side of things when I wrote the article earlier, so I’ll leave it here for inspection. As far as you’re concerned, the CodeIgniter app is ready to go.

All you need to do now is configure your apache server. You’re using virtual hosts? Great. here’s the code..

Create the site configuration file…

sudo touch /etc/apache2/sites-available/yourwebsite.de

Open it for editing (say with vim or your favourite editor)

sudo vim /etc/apache2/sites-available/yourwebsite.de

Paste in the code below…

<virtualhost *:80>
        ServerName yourwebsite.de
        ServerAlias www.yourwebsite.de
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/yourwebsite.de/public_html
        <directory></directory>
                Options FollowSymLinks
                AllowOverride None
        
        <directory /var/www></directory>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</virtualhost>

Save and close the file with

:wq

Now create a symlink from the sites-available to the sites-enabled folder to make the site appear…

sudo ln -s /etc/apache2/sites-available/yourwebsite.de /etc/apache2/sites-enabled/yourwebsite.de

.. and restart apache..

sudo service apache2 restart

Done.

posted under Linux Tips | No Comments »

How do I downsize a Hi-Def movie?

August22

In Debian / Ubuntu, use avconv.

avconv -i input.mp4 -b 64k -s hd720 -strict experimental output.mp4

This command uses avconv, where..

-i input.mp4 = the input file name
-b 64k = down sample the audio channel to 64k – should be fine.
-s hd720 = reduce the video from hd1020 to the 720 format
-strict experimental = Allows mp4 output
output.mp4 = the output file.

If you haven’t got avconv installed, use

sudo apt-get install avconv

and follow instructions.

posted under Linux Tips | No Comments »

How do I quickly process photos for upload to the internet?

August21

In Linux, the easiest way to process images is using imagemagick. It is a command line program you can use to manipulate images very quickly. With it, you can scale images, adjust proportions, add watermarks and alot lot more.

These days, with photos from your camera tpyically of the order of 1.2 – 2.5MB in size, uploading them to the internet in bulk is the stuff of dreams, so better to scale them all down and then upload. Here’s how.

Step 1. Install imagemagick.

Open a terminal window using CTRL + ALT + T

Now, install imagemagik..

sudo apt-get install imagemagik

Now let’s try some examples…

First off, copy the photos you want to modify to a new folder, so you have the originals intact, otheriwse you will modify the originals. Bad idea.

We’ll call this folder /home/darth/pics in these examples.

Reduce the photo called hoth.jpg by 50%

mogrify -resize 50% /home/darth/pics/hoth.jpg

Scale the image to be 1024 pixels wide and whatever number of pixels high, scaled in proportion…

mogrify -resize 1024x /home/darth/pics/hoth.jpg

Scale the image to be 500 pixels high and whatever number of pixels wide, scaled in proportion…

mogrify -resize x500 /home/darth/pics/hoth.jpg

Strip the image of all exif data, so remove make and model of camera, GPS data, flash, shutter and aperture speed, etc. etc.

mogrify -strip /home/darth/pics/hoth.jpg

Do the whole freakin’ folder! (Rotate the photos as required, reize them to be 1024 pixels across the top and do that for all jpegs in the folders and subfolders in /home/darth/pics/deathstar

mogrify --auto-orient -strip -resize 1024x /home/darth/pics/deathstar/*/*.JPG

There are a bajillion more possibilities and commands and options in the suite. Check it out. http://www.imagemagick.org/script/command-line-tools.php

posted under Linux Tips | No Comments »

How do I change my MAC Address?

August13

In Ubuntu, just open a terminal window and install macchanger if needed..

sudo apt-get install macchanger

OK, now use macchanger..

sudo macchanger eth1 -r

This will change the wifi address, as your physical CAT 5 port is prolly eth0. The command above will change the MAC address to a random MAC address.

If you need to find out what the name of your ethernet ports are, including wireless, look no further…

sudo ifconfig

Sweet!

posted under Linux Tips | No Comments »

How do I renew my DHCP Address?

August13

In Ubuntu, just open a terminal window and type

sudo dhclient -r

That should drop (release) the address. To renew it…

sudo dhclient
Simples!
posted under Linux Tips | No Comments »
« Older EntriesNewer Entries »

This is my website for short blog posts and interesting materials that are noteworthy or have some handy-tip value.