Changing Directory Ownership via Command Line

Trying to replace, delete or change files via FTP, you may notice you get insufficient permissions errors. If you haven’t seen this a lot, your first instinct is to try to change the permissions on the directories in question, in which case you will continue to get mooned. This issue is less about permissions per se than about directory ownership. If you’re running on a server that has some directories owned by nobody/99, that means the server itself is considered “owner” and individual users won’t be able to change or delete these. ((If your server requires 777 permissions for certain functions, then you most likely will have some directories “owned” by the server/nobody.))

chown -Rv username:groupname *

The username/groupname should be replaced with your info–but you don’t know this already, best to get out of there and get tech support to help you–and these two will normally be the same. The R makes it recursive, changing the files inside the directory as well as the directory you run the command on, and the v gives you verbose output so you can see what got changed.

Share Button

Restarting dbus via Command Line

As a companion to our “Restarting Haldaemon from the Command Line” piece (coming in handy after software update where you get those annoying ConfigServer firewall warnings “Suspicious process running under user dbus”), here’s what you need to do to restart dbus from the command line:

/etc/init.d/messagebus restart

Note: Your server configuration may vary.

Share Button

Transferring Databases via SSH Command Line

Command Line Fu has a solution for those who have SSH access and need to move a database:

To create a new database with a different name:

ssh -C user@newhost "mysql -uUSER -pPASS -e 'create database NEW_DB_NAME;'" && mysqldump --force --log-error=mysql_error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@remotehost "mysql -uUSER -pPASS NEW_DB_NAME"

To use the same database name for target as the source:

mysqldump --databases --force --log-error=/root/mysql_error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@newhost "mysql -uUSER -pPASS"

If you’re using SSH on a non-standard port (recommended), you’ll need to add a parameter for it in your code after the ssh command, such as -p XXX, where “XXX” is replaced by your port number.

Share Button

Mass Delete Pending Spam Comments from WordPress Database

If you’ve got 14,500 and some pending spam comments in your WP database, I feel your pain. I just transferred a WP site in exactly that state.

Fortunately, you don’t have to scroll through hundreds of pages of the comments moderation que, clicking away to get rid of the junk. A simple line of SQL is all you need to conquer the  spam dragon in a matter of mere seconds. Pop this query into something like PHPmyAdmin where you can run SQL statements directly, and you’re golden.

DELETE FROM wp_comments WHERE comment_approved = '0'

Ideally, run this on the source database before transfer to make your life easier. Why would you want to move thousands of spam comments anyway, right? As a plus, you may be able to import your database using PHPmyAdmin if you can get your database dump to a reasonable file size via deleting an out-of-control spamfest.

Note:  This command will delete ALL unapproved comments. No second chances, review or confirmation. Make sure that’s your goal before you go running SQL statements all willy-nilly. The management is not responsible for outcomes. Use the force wisely, Luke.

Share Button

Restarting Haldaemon from the Command Line

Have a need to restart Haldaemon? I did, p0inted out from the ConfigServer Firewall (CSF) error report:

The file system shows this process is running an executable file that has been deleted. This typically happens when the original file has been replaced by a new file when the application is updated. To prevent this being reported again, restart the process that runs this excecutable file. See csf.conf and the PT_DELETED text for more information about the security implications of processes running deleted executable files.

From command line prompt: /etc/init.d/haldaemon restart

At least, that’s where it was on my system.

Share Button