06th February
2010
written by Chris

I recently had to create a number of home directories from the user accounts in the /etc/passwd file because Webmin didn't create them when the user was created. Don't ask me why. Webmin is a mystery and only does things it feels like doing at the time it does them. But I digress..

The first thing I did was to create file with all users that have directories.

cat /etc/passwd | sed 's/:/ /g' | awk '($5 ~ /\//) { print $1 " " $5}' > file.txt

Edit the file you created and remove things like the postfix directory and other non-user account directories.

Next, run the command to create all of the home directories and then change their ownership to the user.

while read line; do mydir=`echo $line |awk '{print $2}'`; myuid=`echo $line| awk '{print $1}'`;  mkdir $mydir 2>/dev/null; chown $myuid:$myuid $mydir; done < file.txt
25th December
2009
written by Chris

Follow these simple steps to setup an NFS client/server.

First, some housekeeping for this example.
Server machine (server) = 192.168.1.1
Client machine (client) = 192.168.1.2
Exported directory /nfs/export

### The server steps ###
1. Create an entry in /etc/exports with the exported directory and client IP.

/nfs/export 192.168.1.2(rw)

The (rw) sets the directory to be read and writeable. There are other options that can be specified here. Check out the NFS docs for more.

2. Edit /etc/hosts.deny and /etc/host.allow
In /etc/hosts.deny

portmap: ALL

In /etc/hosts.allow

portmap: 192.168.1.2

3. Start up portmap, nfs, nfslock, netfs on the server. These can most likely be found in /etc/init.d in the form of init scripts. Make sure they are set to start at boot with chkconfig (Redhat servers).

4. Run rpcinfo and make sure at least nfs, portmap and mountd are listed.

rpcinfo -p localhost



### The client steps ###

5. Make a directory that you you are going to use to mount the NFS share. Call it whatever you want.

mkdir /mount/nfsdir

6. Start portmap, nfs, nfslock, netfs on the client as you did on the server.

7. Mount the share.

mount 192.168.1.1:/nfs/export /mnt/nfsdir

8. Add an entry to /etc/fstab in order to have the share mount after a reboot.

192.168.1.1:/nfs/export  /mnt/nfsdir   nfs  rw  0 0

9. Test that you can create/delete/edit files and needed by your application.

Tags:
17th December
2009
written by Chris

The following command will optimize all databases in mysql (excpect those that don't support it due to their storage engine).

mysqlcheck -Aao

You can throw the

--auto-repair

flag in if you are brave.

Tags: ,
12th December
2009
written by Chris

If you need to change the TTLs on all domains in Plesk at once, you can massage the database with the following command:

mysql> UPDATE `dns_zone` SET `ttl` = '300′, `ttl_unit` = '60′ WHERE `id` >1;

Substitute the TTL values for what you need. Since the flat files are still used by named to provide DNS resolution, those will need to be updated as well. This command will do the trick:

mysql -Ns -uadmin -p`cat /etc/psa/.psa.shadow` -D psa -e 'select name from domains' | awk '{print "/usr/local/psa/admin/sbin/dnsmng update " $1 }' | sh
Tags: ,
21st November
2009
written by Chris

I had occassion to run across the following question recently:

"Plesk was just upgraded to version 9.2.x and all domains now have an overuse policy set to not allow overuse. I can manually change this to allow overuse, but is there a way to do this through the database so I don't have to do it a domain at a time?".

The answer is yes, sort of. Plesk provides a 'domain_pref' utility that allows the setting of many of the parameters related to domain preferences. This allows one to change parameters for domains using the command line instead of logging into the interface. It works on one domain at a time, so some scripting foo is necessary in order to accomplish this on multiple domains.

In regards to the overuse policy, this handy little one-liner will allow the updating of all domains to a specific overuse policy.

mysql -Ns -uadmin -p<plesk_admin_password_here> psa -e "select name from domains" | awk '{printf("/usr/local/psa/bin/domain_pref –update %s -overuse block\n", $1)}' | sh

There are three options available for the overuse policy.

  • Block: Do not allow overuse
  • Notify: Allow overuse and notify the domain administrator when overuse has occurred.
  • Normal: Allow overuse with no notification.

The script above does the following things:
1. Connects to the Plesk database and selects a list of all domains from the 'domains' table.
2. Runs the 'domain_pref' CLI and sets the overuse policy to 'block'.

It has also come to my attention that the clients will have to have their overuse policy set as well.

mysql -Ns -uadmin -p`cat /etc/psa/.psa.shadow` psa -e "select login from clients" | awk '{printf("/usr/local/psa/bin/client_pref –update %s -overuse normal\n", $1)}' | sh

As always, BACK UP the psa database before doing anything with the CLI.

Previous