Archive for the “Linux” Category

Recently had to dump a mysql database that was larger than the available space. Here’s a quick one-liner to compress the dump and pipe it over ssh to another destination.

# mysqldump DATABASE | gzip -c –fast |ssh user@destination.domain.com ‘cat > /home/user/DATABASE.sql.gz’

Comments 1 Comment »

See a suspicious IP on your box and wonder what it’s doing? Here’s a one-liner that will list the files that IP is accessing:

# lsof -p $(netstat -npat | gawk ‘$5 ~ /127.0.0.1/ {print $7}’ | cut -d”/” -f1 | tail -n1)

Comments No Comments »

Here’s a nifty little trick with vimdiff, say you want to compare the output of to commands. You can do so with a little redirections:

# vimdiff <(cat /etc/passwd) <(cat /etc/shadow)

I know this is silly since you can simply vimdiff the files directly without the redirects. But say you want to compare who is currently logged in with who was last 10 people logged in.

# vimdiff <(who) <(last|head)

Boom.

Note: the space between th ‘)’ and the ‘<’ is required.

Comments No Comments »

Often times when being hit by a plethora of connections, it is good to tally them all up and see if there is a specific locale that may be of questionable origin.

netstat -an | grep “ESTABLISHED” |awk ‘{print $5}’ |cut -d “:” -f1 |sort |uniq -c |sort -n

Comments 2 Comments »

Nifty little one liners to find who’s running that problematic cronjob:

for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done

Comments 1 Comment »

I have seen many pages illustrating how to cause a kernel panic. Some have some short (relative to others) programs to do this. Honestly you can cause a kernel panic with the magic sysrq commands. For those that missed my earlier article, you can find it at Magic Sysrq.

In this situation, we will need to enable the sysrq:

echo 1 > /proc/sys/kernel/sysrq

Then issue the kernel panic.

echo c > /proc/sysrq-trigger

This causes a kexec reboot with a crashdump. If you have more information on this process, please let me know.

Comments No Comments »

In order to have multiple people able to update the same directories/files:

1. Create directory that multiple user to access.

# mkdir /var/www/html/site1.com

2. Create the group that needs to be able to write to the directory.

# groupadd webdev

3. Change the group associated with the directory.

# chgrp webdev /var/www/html/site1.com

4. Make the directory group writable.

# chmod g+w /var/www/html/site1.com

5. Change the SGID of directory so that any new files retain the group ownership

# chmod g+s /var/www/html/site1.com

6. Create the new user, adding the additional group(set the home directory if necassary).

# useradd -G webdev -d /var/www/html/site1.com user1

7. Change the umask so that newly uploaded files retain group writable permissions:

# vi /etc/ssh/sshd_config

Update the sftp subsytem line to look like so:

Subsystem sftp /bin/sh -c ‘umask 0002; /usr/libexec/openssh/sftp-server’

For chrooted sftp:

Subsystem sftp /bin/sh -c ‘umask 0002; internal-sftp’

Note: if you are trying to make these changes to a directory structure that already exists, any changes to permissions will need to be done recursively.

Comments No Comments »

We were discussing clearing out swap today so I came up with this quick one-liner to clear out swap:

# free -m | grep -i swap; sudo swapoff -a && sudo swapon -a; free -m | grep -i swap

Swap:        5887         49       5838

Swap:         5887          0       5887

One caveat though, you may want to verify that there is enough memory available to free up swap. Likely the items in swap are old and you will not need it, but no sense having your server run out of memory unnecessarily.

Comments No Comments »

By default, linux reserve 5% of the hard drive in order to prevent the server from crashing. If you’ve ever seen an application lock up because your drive is at 100% and it can’t write to the logs, you’ll know what I’m talking about. Imagine the same situation, but there is no room on the disk drive… at all. That move you just tried to perform can’t happen cause there is no place for it to go.

Well, luckily we have the 5% reserved block and on your 250G drive is 12.5G. Well, from what I’ve read this is way to much for this. I can’t find a definitive amount, but a lot of articles suggest going down to 3% or even 1%.

This is how you ‘set’ the size at file-system creation:

# mkfs.ext3 -m 1/dev/sda1 (replace sda1 with your partition name)

The above command creates a file system with only 1% of its space reserved for the root user. To ‘change’ the reserved blocks after the file-system creation, you can use tune2fs utility:

# tune2fs -m 1 /dev/sda1 (replace sda1 with your partition name)

Further reading

Comments No Comments »

APPLIES TO:

  • Parallels Plesk Panel for Linux/Unix

Symptoms

The following error occurs during domain deleting in Plesk CP:

ERROR: PleskUtilException webstatmng is failed –unset-config –domain-name=domain.tld –stat-prog=

or during domain page accessing:

 

Error: Unable to update hosting preferences: hosting update is failed: webstatmng is failed –unset-config –domain-name=guide2care.com –stat-prog=

Cause

This error means that incorrect value was specified in the ‘webstat’ field of the ‘hosting’ table in ‘psa’ database.

Resolution

The ‘webstat’ field can be set to ‘none’,'webalizer’ or ‘awstats’ values. To solve this problem, update ‘webstat’ field in ‘psa.hosting’ table for the problem ‘DOMAIN’ with the query like:

mysql -Ns -uadmin -p`cat /etc/psa/.psa.shadow` psa -e 'update domains d, hosting h set h.webstat="none" where h.dom_id=d.id and d.name="DOMAIN"'

Note, “DOMAIN” should be replaced with the real domain name.

Note, if you use MySQL 3.x, the query should be spilt in two:

select id from domains where name="DOMAIN";
update hosting set webstat="none" where dom_id="DOMAIN_ID";

Where DOMAIN_ID is the number that you get after the first query.

Backup domains statistics directory (HTTPD_VHOSTS_D/DOMAIN/statistics/).

After that you will be able to delete domain or access it through Plesk CP and manage webstat on the domain’s hosting setup page.

http://kb.parallels.com/1726

Comments No Comments »