Browsing the archives for the Linux tag.

Chkconfig Notes

Config

linux

Chkconfig is a simple utility available on Linux that allows you to register services to start/stop on bootup and shutdown. The following are the basic commands you need to know to get things going:

chkconfig --list (lists all the commands that are registered)
chkconfig --add httpd (add httpd to the chkconfig list)
chkconfig  --level 35 httpd on (enables the httpd daemon to start on runlevels 3 and 5)
chkconfig --level 35 mysqld on (enables the mysqld daemon to start on runlevels 3 and 5)
chkconfig --level 35 memcached on (enables the memcached daemon to start on runlevels 3 and 5)
chkconfig --level 2345 sendmail on (enabled the sendmail daemon to start on runlevels 2, 3, 4 and 5)
No Comments

Bash Find On A Large Dataset – Write The Results To A File

Examples

A fast bash based solution for executing a find on a directory with a lot of files that you want to log to a file:

find /my/data/  -name '*.xml' -type f -fprint my_xml_files.txt

This example looks in the /my/data/ directory for all files with the xml extension and then writes the results to the my_xml_files.txt file.

No Comments

Linux Process Thread Count

Examples

On Linux, to get a thread count for particular process, issue:

ps UH p PID_OF_PROCESS | wc -l

Removing the pipe to the “| wc -l” yields more information about the running threads.

No Comments

Configure Linux Hostname

Config

If you want to change your Linux hostname and you’re running Fedora or Red Hat, the steps are listed below.

Immediate Change

echo 'some.host.com' > /proc/sys/kernel/hostname

Persisted Change

This is for non-DHCP nodes.

Add your name to /etc/sysconfig/network

NETWORKING=yes
HOSTNAME="some.host.com"

If you’re node gets an IP address from a DHCP server then you can set:

DHCP_HOSTNAME="some.host.com"

in the /etc/sysconfig/network-scripts/ifcfg-eth0 file (or whatever your primary device is).

Notes

You can also add your hostname to your /etc/hosts file

10.1.1.10 some.host.com some
No Comments

Linux – Programmatically Change Password

Examples

If you need to script a password change you have two main options:

  1. Write a script that interacts with the command line and executes passwd
  2. Use the usermod command

Option one is a bit of a mess and option two requires an encrypted version of the password. At first, we couldn’t figure out how to encrypt the password but then we realized that you could use the Perl crypt function.

An example of number two:

#!/bin/bash

usermod -p `perl -e 'print crypt("test", "salt")'` root;

That’s all there is to it!

2 Comments