Cleaning a virus that makes the whole removable disk read-only.

Once before, I’ve encountered a virus that transfers the entire contents of the usb removable disk to a folder with a blank filename, and then creates a self-running link in the root directory that copies the virus to the hard disk, so that it propogates itself to any new removable disk that is connected. But this was a new breed that made the removable usb drive read-only, so much so that most except the most hard core linux utilities would fail to fix it. A friend had handed the disk over to me, requesting me to see if my “linux PC can fix it”.

The command which fixed the write protect status was:

sudo blockdev --setrw /dev/sdc1

This allowed me to remount it as read-write:

sudo mount -o rw,remount /dev/sdc1 /home/joel/usb

so that I could finally run clamscan and fix it:

clamscan --remove /home/joel/usb

To rename the folder with a blank space as name, I simply used:

mv '/home/joel/usb/ ' /home/joel/usb/ab

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

git pull error: fatal: protocol error: bad line length character: Fail

Solution to fix:
“fatal: protocol error: bad line length character: Fail”

The error:

# git pull
fatal: protocol error: bad line length character: Fail

Solution:
Change the login shell of user git from /bin/sh to /bin/bash

[email protected]:~# chsh -s /bin/bash git

Now retrying:

# git pull
remote: Counting objects: 20, done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 20 (delta 11), reused 0 (delta 0)
Unpacking objects: 100% (20/20), done.
From gitmaster.droidzone.in:droidzone/bash-advanced-scripts
   84fa4aa..cccfa41  master     -> origin/master
Updating 84fa4aa..cccfa41
Fast-forward
 batchtorrent.pl   |  237 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gitlabrestart     |    4 +++
 loadtorrents.pl   |  134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 readfile.pl       |  140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 rotten2torrent.pl |  269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 784 insertions(+)
 create mode 100755 batchtorrent.pl
 create mode 100755 gitlabrestart
 create mode 100755 loadtorrents.pl
 create mode 100755 readfile.pl
 create mode 100755 rotten2torrent.pl

Edit: This is not the proper fix.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

LWP not available

How to fix the message “LWP not available” while running cpan:

First, update cpan:
install Bundle::CPAN
reload CPAN
install Bundle::LWP


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Checking and fixing a corrupt portable hard disk

My WD suddenly stopped getting recognized by Windows after a power surge. I was perturbed by the thought that it may have been permanently damaged by a hardware fault. But since it contained a lot of important data, I decided that I would try to fix it using software tools before sending it to WD for replacement.

I tried getting chkdsk in Windows to check it, but during the couple of times that I could get Windows to assign a drive letter to it, chkdsk stopped running half way through citing a “read error”.

Next option was to try getting gparted to repair it. However it failed stating the fsck.ntfs wasnt installed.

Next I ran ntfsfix on the partition (it was partitioned as ntfs). Though repair took over an hour to complete, at the end of it, it was recognized by Linux. I then tried connecting it to Windows and found that Windows recognized it as well.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Adding auto complete for apt-get install

Question:

I have noticed that while on Ubuntu, if I type the following:

mc

and it isnt installed, I get the message below:

The program 'mc' is currently not installed. You can install it by typing: sudo apt-get install mc

However in Debian, that is not available. It just gives a “-bash: /usr/bin/mc: No such file or directory” message. How can I implement the same functionality in bash command line on Debian? Yes, I know that if it is package suggestion that I want, I can simply do a regex search using *apt-cache search*. However I was hoping for the simpler suggestion immediately on typing the name of the program.

As per discussions, the functionality is provided by the package command-not-found. However even after installing it, and also installing bash-completion package, this isnt available on the Debian bash shell.

Answer:

The suggestions are definitely provided by the package command-not-found.

However after installing the package, one needs to run the following command once to initialize the database:

update-command-not-found

After doing this, bash starts providing suggestions to install the correct package.

$htop
Could not find the database of available applications, run update-command-not-found as root to fix this
htop: command not found

$update-command-not-found
Downloading complete file http://ftp.de.debian.org/debian/dists/squeeze/Contents-i386.gz
I: Writing data for ftp.de.debian.org_debian_dists_squeeze_Contents-i386.gz ... . done

$htop
The program 'htop' is currently not installed. You can install it by typing:
apt-get install htop
htop: command not found

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Fix for “ssh-add: Could not open a connection to your authentication agent.”

You might have tried adding a key with:

ssh-add .ssh/id_rsa

only to get this error:

ssh-add .ssh/id_rsa
Could not open a connection to your authentication agent.[/code]
If this happens, it is because your ssh agent is not running in the terminal.

Run this:
exec ssh-agent bash

which will cause it to resource your .bashrc files and start the agent.

Now try readding the key again:

ssh-add .ssh/id_rsa
Identity added: .ssh/id_rsa (.ssh/id_rsa)

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Implementing a “Contact the author” form for WordPress

You dont need bloated plugins for implementing a comment system for WordPress.

I use the following simple prototype for a comment system on WordPress.

The first part is a form using tables and form fields to take care of the user input:

You can use the following form to contact the author:

Next is the php script which runs on the server and takes care of mailing the form data to a specified email address:

<?php
if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "Someone has submitted feedback on your website";

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";

// create email headers

$headers = 'From: [email protected]'."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.

<?php

}

?>

Note that it includes certain checks to see if mandatory fields have been filled in.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Install Libre office in Debian Squeeze

Remarks: Note the following procedure seemed to corrupt dependencies for my kernel to a point where it was easier to reinstall the OS than remove conflicting packages and install correct ones. 

Add a new repository to apt sources:

Create a new file in sources.list.d

kdesudo kate /etc/apt/sources.list.d/libre-office.list

Add this line:

deb http://backports.debian.org/debian-backports squeeze-backports main

Running command:

[[email protected] c]$ sudo apt-get install libreoffice

 

Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
libreoffice : Depends: libreoffice-core (= 1:3.5.4+dfsg-3~bpo60+2) but it is not going to be installed
Depends: libreoffice-writer but it is not going to be installed
Depends: libreoffice-calc but it is not going to be installed
Depends: libreoffice-impress but it is not going to be installed
Depends: libreoffice-draw but it is not going to be installed
Depends: libreoffice-math but it is not going to be installed
Depends: libreoffice-base but it is not going to be installed
Depends: libreoffice-report-builder-bin but it is not going to be installed
Depends: libreoffice-filter-mobiledev but it is not going to be installed
Depends: libreoffice-java-common (>= 1:3.5.4+dfsg~) but it is not going to be installed
E: Broken packages

 

The dependency problems seemed difficult to fix, so I tried:

[[email protected] c]$ sudo aptitude -t squeeze-backports install libreoffice

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Fixing the error “warning: setlocale: LC_CTYPE: cannot change locale”

Recently I was granted build server access on Goo. While trying Bash completion, I encountered this error. Every time I tried to use Tab key for completion, this error message would get added to my typed command. It didnt interfere with the actual command execution. Bash seemed to be totally oblivious to the command line getting hijacked in this fashion. But for the user, me, it was an eyesore.

The fix was too simple. I simply needed to add the following to my ~/.bashrc file:

export LC_CTYPE="en_US.UTF-8"

Thanks to bergspot


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Enabling “New Folder” Menu Handler in Explorer for Seagate Expansion Drive

I found that after installing Memeo software (Backup), I couldnt click on the Explorer menuitem “New Folder” to create a new folder. I had to rightclick and choose the contextual item. I wasnt sure what caused it, until I read up ways on how to fix context menu issues.

The utility you need is called ShellExView

While you’re at it, you should also see the list of free apps by nirsoft, the developers of ShellExView. Most of them are very useful nifty utilities that make your life on Windows much easier.

Once in ShellExView, try seeing if any of the listed items (in pink are the apps which affect Windows system) affect the Context menu. I found that Ruvuma.ContextMenuExt.Contextmenu was actually described as Memeo LifeAgent Explorer Extension affected the “Context Menu” type. I disabled it, and Voila! The context menu started to work after a LogOff!


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.