What does “Is this ok [y/d/N]:” mean?

When installing new software using yum, you will occasionally get the the option of “Is this ok [y/d/N]:”  Everyone knows recognizes Yes and No, but the option d may have thrown you for a loop.

“d” simply stands for download only.  If you were to do this from the commandline you’d use this:

yum –download-only

Occasionally this is useful if you are prepping a resource, like a thumb drive, with all of the RPMs that you standardly install.  You might also want to have the RPMs available for switching between versions of software.  I’m sure there are many more reasons too.

Hopefully this has answered your question.

Advanced Google Search Operators

Sometimes a simple Google search won’t do. Today I needed to find some malformed URLs in a site.   I couldn’t remember how to search for specific text in a URL.

I had a hard time finding the Google documentation of search commands this morning.  It I needed the allinurl: function.

I don’t want to have to search that hard again so here is the documentation in my Code Cave:

Search Service Search Operators
Web Search allinanchor:allintext:allintitle:allinurl:cache:define:filetype:id:inanchor:info:intext:intitle:inurl:link:related:site:
Image Search allintitle:allinurl:filetype:inurl:intitle:site:
Groups allintext:allintitle:author:group:insubject:intext:intitle:
Directory allintext:allintitle:allinurl:ext:filetype:intext:intitle:inurl:
News allintext:allintitle:allinurl:intext:intitle:inurl:location:source:
Product Search allintext:allintitle:

Source and additional information:  http://www.googleguide.com/advanced_operators_reference.html

Finding large files on a Linux server

Here are a couple commands you might find useful.

This command finds files that are larger than half a gig:

find / -type f  -size +500M -exec ls -lh {} \;

This command finds files that are larger than 1 gig:

find / -type f  -size +1G -exec ls -lh {} \;

This command finds files that are larger than 1 gig excluding the home directory which might be on a different mount. (notice the removal of the -type f so that the not works on paths):

find / -not \( -path /home -o -path /boot -o -path /tmp \)  -size +1G -exec ls -lh {} \;

 

How to Fix: After upgrading WHMCS: Down for Maintenance An upgrade is currently in progress

I recently came across an issue I’d not seen before. After performing what I thought was a proper upgrade, I found that my support and sales portal was displaying the error:

Down for Maintenance (Err 2)
An upgrade is currently in progress… Please come back soon…

I found several difference references to this error on the web. The one detail that I was able to glean was that this error usually occurs when the files are updated, but the database is not. This was the case in my situation. It turns out that I caused my own problem. The key to the mystery is that the files to perform the database upgrade are actually part of the “install” directory.

The instructions for a full upgrade are  here: http://docs.whmcs.com/Upgrading

Basically  you just:

  1. Extract the files
  2. Rename the admin and cron directories as needed
  3. Copy those files over the existing installation
  4. Visit the site and follow the upgrade instructions, if any.

My problem was that #4  includes an error at the end that tells you the install directory still exists, delete it.  Being a guy who likes to optimize a process as much as possible, I was deleting the install directory before copying  in the files.  This process worked great 99% of the time.  However, eventually they changed the database structure from 5.2.13 to 5.2.14 or 5.2.15.  THEN the result was that the WHMCS software could not upgrade the database. and I got the wonderful WHMCS Down for Maintenance error.

So really the steps should be:

  1. Extract the files
  2. Rename the admin and cron directories as needed
  3. Copy those files over the existing installation
  4. Visit the site and follow the upgrade instructions, if any.
  5. Delete the install directory when prompted.

At that point, everything should work fine.   At least it did for my particular incarnation of the problem.  I hope it solves your issues too.

How to quickly update WHMCS on WiredTree hosting and others.

NOTE: This script has been updated to remove the premature deletion of the install directory.

Over the last month or two, WHMCS has been updated many times. This is a GOOD THING, but it can be annoying to go through the normal update process every week or two.

So, I created a small function that I’ve added to /etc/bashrc on my server.

It does the following:
1. Verifies the script is running from the right server.
2. Changes directories to the location where I have WHMCS installed.
3. Removes any files and folders from a previous update
4. Downloads the latest update from the password protected WiredTree repository
5. Unpacks it
6. Renames the admin directory to a new name for security purposes (you may need to do the cron dir too)
7. Changes the owner and group of the new files to be the one required for this website.
8. Copies in all of the new files, overwriting what is there.

So updates now take a few seconds rather than 20 distracting minutes. Maybe you will find this useful.

Here is the function I added to /etc/bashrc:

 

function upwhmcs(){
  curhostname=$(hostname -s)
  desiredhost='REPLACE_WITH_HOSTNAME'

  if [ "${curhostname}" == "$desiredhost" ]; then
    cd /home/REPLACE_WITH_DIRNAME
    rm -Rf whmcs
    rm -f whmcs_current.zip
    wget http://REPLACE_WITH_USERNAME:REPLACE_WITH_PASSWORD@whmcs.wiredtree.com/whmcs_current.zip
    unzip -o whmcs_current.zip
    cd whmcs
    mv admin REPLACE_WITH_ADMIN_DIR_NAME
    chown -R REPLACE_WITH_DIROWNER:REPLACE_WITH_DIROWNER .
    cp -Rf * ../www
    cd ../www
    pwd
    return
  fi
  echo "Wrong Server. Update skipped"
}

 

To use that listing you need to replace the following text
REPLACE_WITH_HOSTNAME – Replace this with what you get when you run ‘hostname -s’ from the command line.
REPLACE_WITH_DIRNAME – Replace this text with the directory of your whmcs installation. Maybe it is /home/whmcs/ or /home/hosting/ or /home/sales/
REPLACE_WITH_USERNAME – This should become the username that WiredTree gave you to login and get WHMCS updates
REPLACE_WITH_PASSWORD – This should become the password that WiredTree gave you to login and get WHMCS updates
REPLACE_WITH_ADMIN_DIR_NAME – This is the custom name of the admin directory on your server. If you just use admin, delete this mv line entirely.
REPLACE_WITH_DIROWNER – This is quite likely the same value as REPLACE_WITH_DIRNAME

This script assumes that you have WHMCS installed as its own website/subdomain. You can probably adjust it to your needs if you run it in a sub-directory. If you make this customization, send it back to me and I’ll add it to the article.

After the upgrade process, you must visit the site, follow the update steps and then go back and delete the “install” directory from the installation.  That should do it!

How To: List the lines that exist in one file and not another in Linux or Windows Command Line

This solution uses grep.

Grep is a search tool that exists by default in just about every Linux installation. You can also search Google for Windows Grep.

for a Demo, Here is FileA.txt

1. In Both
2. In Both
3. In Both
4. In File A Only
5. In Both
0. Out of Order In Both
-1.  Out of Order In A Only
In A only

Here is FileB.txt

1. In Both
2. In Both
3. In Both
4. In File B Only
5. In Both
0. Out of Order In Both
-1.  Out of Order In B Only
In B only

To show lines that only exist in File B and not in A. Do this:

# grep -v -xFf FileA.txt FileB.txt

4. In File B Only
-1.  Out of Order In B Only
In B only

To show lines that only exist in File A and not in B. Do this:

# grep -v -xFf FileB.txt FileA.txt

4. In File A Only
-1.  Out of Order In A Only
In A only

 

In windows, Grep you can drop the capital F from the command line. But it really shouldn’t matter.

The command line arguments are:

-v = Reverse the compare so you get what doesn’t match instead of what does

-x = Compare entire lines at a time instead of characters

-F = Do not parse the contents of each line for any mid-line regex commands

-f = Compare the specified files

 

Hope that helps someone!

How to fix: WordPress updates and plugin installs require FTP login but shouldn’t.

WordPress is generally very good about working under any server situation you put it in. It even has fall back code if the preferred server settings are not available.

The plugin and update installation code is one example of this. If WordPress doesn’t have the rights to directly update files, it will ask you for FTP login information.

However, there are times when you KNOW the permissions are correct to allow Apache to update files and WordPress doesn’t detect it and insists on FTP. This should be extremely rare. However if you ever do come across this circumstance you can force WordPress to override this behavior and use direct updates.

Just add these lines to wp-config.php:

define( ‘FS_METHOD’, ‘direct’ );
define( ‘FS_CHMOD_DIR’, 0777 );
define( ‘FS_CHMOD_FILE’, 0777 );

You can read more about these constants on the WordPress Codex.

How to: Split path and filename in MS Excel, Google Docs or OpenOffice Calc

I did a code review along with Brad Williams yesterday and today we combined our results.  The problem was, our spreadsheet columns didn’t match.  He’d combined path and filename into one column and I’d split them out into two columns. We decided the split path and filename was useful.  So I had to come up with  a quick set of formula to create the two extra columns, splitting path from filename.

For a  short time, I thought it wouldn’t be possible, and that my formula foo had  finally failed me.  The difficulty is of course that the find()  doesn’t have an option for returning the position of anything but the first occurrence of the search text.  So, you don’t have anyway to know where to split the string.  Ahhh, but lo and behold the substitute function can be used to replace the nth occurrence of a character or string.  If you replace the right duplicated character with something unique, you can come use find() to determine the right place do do the split.

The method I used was based upon formulas found on Excel Ticker in an article written by Mourad Louha.  It took me several reads through to grok the concept of his method. (Actually I came back to the article hours later to figure out how the formula worked – long after hacking the formulas to do what I wanted). So, I thought I would boil it down for you here.  Also his formula was based upon an unusual layout in his spreadsheet.  What I’ve listed here simply assume a 3 column spreadsheet (Folder, File, Full Path) with a row for the title.  If your third column (c2) has the concatenated/full path, just paste the right formula into the first and second columns (a2 and b2) in the second row and you are done.

Here is  Mourad’s method boiled down into simple steps:

1. Determine how many slashes there are.  Subtract the length of the string, with slashes removed, from the original length of the string.

2. Replace the LAST occurrence of the slash with unique text we can find (we substitute $$$ but anything unique could be used)

3.  We now use find()  to get the position of the unique text and use that as the location to split the string.

 

Open Office Calc/Google Spreadsheet Filename Split Formulas

Linux Formula for splitting the path off a filepath:
= LEFT($C2;FIND(“$$$”;SUBSTITUTE($C2;”/”;”$$$”;LEN($C2) – LEN(SUBSTITUTE($C2;”/”;””))))-1)

Linux Formula for splitting a file name off a filepath:
=RIGHT($C2;LEN($C2)-FIND(“$$$”;SUBSTITUTE($C2;”/”;”$$$”;LEN($C2)-LEN(SUBSTITUTE($C2;”/”;””)))))

Windows Formula for splitting the path off a filepath:
= LEFT($C2;FIND(“$$$”;SUBSTITUTE($C2;”\”;”$$$”;LEN($C2) – LEN(SUBSTITUTE($C2;”\”;””))))-1)

Windows Formula for splitting a file name off a filepath:
=RIGHT($C2;LEN($C2)-FIND(“$$$”;SUBSTITUTE($C2;”\”;”$$$”;LEN($C2)-LEN(SUBSTITUTE($C2;”\”;””)))))

 

Microsoft Excel Filename Split Formulas

Microsoft Exceluses commas instead of semicolons.

Linux Formula for splitting the path off a filepath:
= LEFT($C2,FIND(“$$$”,SUBSTITUTE($C2,”/”,”$$$”,LEN($C2) – LEN(SUBSTITUTE($C2,”/”,””))))-1)

Linux Formula for splitting a file name off a filepath:
=RIGHT($C2,LEN($C2)-FIND(“$$$”,SUBSTITUTE($C2,”/”,”$$$”,LEN($C2)-LEN(SUBSTITUTE($C2,”/”,””)))))

Windows Formula for splitting the path off a filepath:
= LEFT($C2,FIND(“$$$”,SUBSTITUTE($C2,”\”,”$$$”,LEN($C2) – LEN(SUBSTITUTE($C2,”\”,””))))-1)

Windows Formula for splitting a file name off a filepath:
=RIGHT($C2,LEN($C2)-FIND(“$$$”,SUBSTITUTE($C2,”\”,”$$$”,LEN($C2)-LEN(SUBSTITUTE($C2,”\”,””)))))

Cold storage before my best ideas melt away…