OCR Tesseract – Text Recognition in Ubuntu 14.04

  1. Installation via command line
    sudo apt-get install tesseract-ocr
  2. Install a language file (e.g. -eng, -deu, -fra, -ita, -ndl, -por, -spa, …)
    sudo apt-get install tesseract-ocr-eng
  3. Run OCR on the scanned file
    tesseract scan.png scanned.txt -l eng

 

References

 

Accessing external LUKS HDD with custom user, Ubuntu 14.04

For some esoteric reason you might want to access your dm-crypt/LUKS encrypted harddisk with another user – e.g. perl, php, etc.

When plugging in external devices with automount standard permissions are used. Therefor a user like www-data will not be able to access the data of the drive. A solution is to permanently register the drive with crypttab and fstab and give the drive custom permissions.

  1. Check which user is running your target application. (e.g. user “www-data”)
    ps -aux
  2. Connect the drive manually and check the files /etc/crypttab and /etc/fstab.
    mount -l will help you to check the current fstab permissions.
  3. Disconnect the drive and recheck the permissions. Notice the missing line in /etc/crypttab.
  4. Add the missing line to /etc/crypttab – example given (replace LUKS ID and UUID):
    luks-504c9fa7-d080-4acf-a829-73227b48fb89 UUID=01234567-89ab-cdef-0123-456789abcdef none luks,discard
  5. Create the target mount directory.
    sudo mkdir /archive
  6. Add the line to /etc/fstab:
    /dev/mapper/luks-504c9fa7-d080-4acf-a829-73227b48fb89 /archive ext4 noauto,uid=mainsername,gid=www-data,umask=0027 0 0
    This example configuration will give the user “www-data” read access to the drive.
  7. Mount the drive:
    sudo mount /dev/mapper/luks-50* /archive
    sudo mount -a

To put it in a nutshell, fstab needs the /dev/mapper/luks-… before it can mount the drive.

References

Save energy by spinning down HDDs, Ubuntu 14.04

Especially when using a fast SSD as the main harddisk, it makes sense to spin down a secondary (larger) harddisk which is seldom used.

First of all you have to know which drive is mapped to the /dev directory. E.g. you can use the program gparted to show you the relevant /dev drive.

To spin down a hard disk into standby mode use this command in the terminal application (in this case the drive is “sdb”):

sudo hdparm -y /dev/sdb

To start your computer with the secondary drive in standby mode just add the described command to the file /etc/rc.local.

In that file you can also define an automatic spin down time –  e.g.

hdparm -S 120 /dev/sdb

The parameter 120 is nonlinear, so experiment with the number until it fits your needs.

 

Further Reference

hdparm – Ubuntu manuals

Graphviz + PHP + Ubuntu Linux 14.04 via exec

As the installation of the PHP Graphviz library on Ubuntu seems quite tricky. This shows a fast (& dirty) way of using Graphviz.

sudo apt-get install graphviz

Save and execute the following PHP code in a directory with full permissions (777).

<?php

$input = <<<DATA
digraph G {
main [label="main\n(start here)"];
main -> parse -> execute;
main -> init;
main -> cleanup;
execute -> make_string;
execute -> printf
init -> make_string;
main -> printf;
execute -> compare;
}
DATA;
file_put_contents('input.dot', $input);

exec('dot -Tpng input.dot -o graph.png');

echo ('<img src="graph.png" />');

?>

References:
Graphviz documentation

Windows 7 password reset with Xubuntu Linux LiveCD

Strong Warning & Disclaimer: This Windows 7 password reset changes the user privileges of the system. It is not expected, but may damage the Windows system! Use it at your own risk! It is recommended to backup crucial data with the LiveCD before running the password reset program. THE AUTHOR IS NOT RESPONSIBLE FOR ANY DAMAGE CAUSED BY THE (MIS)USE OF THE DESCRIBED SOFTWARE!

Remark: The Windows7 System will need access to the Internet for installing chntpw.

  1. Download the Xubuntu Linux 14.04 LTS LiveCD image. (ISO)
    You can as well use the classical Ubuntu Linux LiveCD version. However the distro Xubuntu Linux is recommended, because it is very similar to the classic Windows desktop and simpler.
  2. Download the USB Live disk creator unetbootin.
  3. Create a bootable USB stick with unetbootin and the downloaded ISO image from the first step.
  4. Boot the computer (with the Windows operating system) from the USB stick. You may have to change the BIOS settings to be able to boot from the USB stick.
  5. In the Xubuntu boot menu choose the “Try Xubuntu without Installing” option to start Xubuntu Linux without damaging anything on the Windows System.
  6. For international users (optional): Look for the Settings Manager application and choose Keyboard and then Layout. There you can set the best keyboard layout.
  7. On the graphical Xubuntu desktop click twice on all displayed disk drives. This will  mount the drive partitions.
  8. In Xubuntu start the “Terminal Emulator” application.
  9. In the terminal enter:
    sudo apt-get install chntpw
    This will install the Windows password reset application. Then stay in the terminal and enter a few further commands:
  10. Change to the directory, where all the disk drives are mounted for the standard users “xubuntu
    cd /media/xubuntu
  11. The following command will show you all available (Windows) drives that were found.
    ls
  12. Let’s say the Name of your drive is DRIVENAME (as a placeholder). Then you will have to change into the appropriate Windows directory where the (SAM) password file is located. Enter:
    cd DRIVENAME/WINDOWS/system32/config
  13. Now we can get an overview of the user accounts with the password reset application:
    sudo chntpw -l SAM
  14. Select a user you want to change. Let’s say the username is USERNAME (as a placeholder). So enter:
    sudo chntpw -u USERNAME SAM
  15. The chntpwd application guides you through the application. You can now eitherupgrade an existing user to an admin or reset the password of an existing user.
  16. After finishing your modifications check them by entering again:
    sudo chntpw -l SAM
  17. Reboot and login with the targeted Windows 7 user. If you upgraded a user to an admin you can login with the new admin and change the password of other existing admins.

References

Brother HL3040CN Installation, Ubuntu Linux 14.04

  1. sudo mkdir /var/spool/lpd
  2. sudo apt-get install lib32stdc++6
  3. Download the printer driver files LPR printer driver (deb package) and theCUPSwrapper printer driver (deb package) from the Brother website:
    http://support.brother.com/g/b/downloadlist.aspx?c=us&lang=en&prod=hl3040cn_all&os=128
  4. sudo dpkg -i --force-all hl3040cnlpr*
  5. sudo dpkg -i --force-all hl3040cncups*
  6. Now the Brother 3040CN printer appears in the printers overview. However you might have to add a new printer – e.g. as a network printer.
  7. For the new added printer choose Provide PPD file as printer driver. Add the following file: /usr/share/cups/model/Brother/brother_hl3040cn_printer_en.ppd

Reference: Solved: Brother HL-3040CN Won’t Print
http://ubuntuforums.org/showthread.php?t=1602075&p=10012790#post10012790

nginx + Perl Installation, Ubuntu Linux 14.04

  1. sudo apt-get install nginx libfcgi-perl
  2. sudo wget http://nginxlibrary.com/downloads/perl-fcgi/fastcgi-wrapper -O /usr/bin/fastcgi-wrapper.pl
  3. sudo chmod +x /usr/bin/fastcgi-wrapper.pl
  4. Copy and save the following code into the file perl-fcgi
    (Source: http://wiki.ubuntuusers.de/nginx)

    #!/bin/bash
    PERL_SCRIPT=/usr/bin/fastcgi-wrapper.pl
    RETVAL=0
    case "$1" in
        start)
          $PERL_SCRIPT
          RETVAL=$?
      ;;
        stop)
          killall -9 perl
          RETVAL=$?
      ;;
        restart)
          killall -9 perl
          $PERL_SCRIPT
          RETVAL=$?
      ;;
        *)
          echo "Usage: perl-fastcgi {start|stop|restart}"
          exit 1
      ;;
    esac
    exit $RETVAL
  5. sudo mv perl-fcgi /etc/init.d
  6. sudo chmod a+x /etc/init.d/perl-fcgi
  7. sudo update-rc.d perl-fcgi defaults
  8. sudo service perl-fcgi start
  9. sudo service nginx restart

Additional reference: http://nginxlibrary.com/perl-fastcgi