Archive for the ‘linux’ Category

/usr/local/pem/bin/logparser.sh

webalizer -p -N 5 -o /usr/local/pem/vhosts/103177/webspace/webstat -n d1011250.domain.com -c
/usr/local/pem/vhosts/103177/webspace/conf/webalizer.conf /usr/local/pem/vhosts/103177/log/access_log.new

tar cf file.tar files – create a tar named file.tar containing files
tar xf file.tar – extract the files from file.tar
tar czf file.tar.gz files – create a tar with Gzip compression
tar xzf file.tar.gz – extract a tar using Gzip
tar cjf file.tar.bz2 – create a tar with Bzip2 compression
tar xjf file.tar.bz2 – extract a tar using Bzip2
gzip file – compresses file and renames it to file.gz
gzip -d file.gz – decompresses file.gz back to file

There are repository rpm packages for RHEL4 and RHEL5 . The repository package installs the repo details on your local
system for yum or up2date to use. Then you can install packages with your usual method, and the EPEL repository is
included.

su -c 'rpm -Uvh http://mirror.nl.leaseweb.net/epel/5/i386/epel-release-5-4.noarch.rpm'
...
su -c 'yum install foo'

centos repo yum

10 Port Forwarding

By:
Stephen Carville
Rev:
08/23/02

Port Forwarding is also possible using OpenSSH (Sec 17.2).

10.1 Using xinetd redirect function

The simpliest and, in my opinion, the preferred way to handle redirecting unencrypted connections is to use the redirect
capability built into xinetd.

If necessary, add services names to /etc/services. For example:
geofwd 50005/tcp # GeoTrac forwarded port

1. Add service file to /etc/xinetd.d. Example file:
# default: on
# description: forward connections to indian:1005
service geofwd
{
flags = REUSE
socket_type = stream
wait = no
user = root
redirect = 192.168.124.4 1005
log_on_failure += USERID
}

2. Restart xinetd
# /etc/rc.d/init.d/xinetd restart

10.2 Using Netcat

The netcat utility is sometimes described as the ‘Swiss Army Knife” of the network. Here we are using it for very basic
port forwarding from an externally accessible server to an internal server. If it is not necessary to run the forwarding
service continiously, on Redhat it is prefereable to use xinetd forwarding.

1. Install netcat from CDROM or from ftp
# rpm -Uvh ftp://volga/pub/RPMS/nc-*.rpm
2. Add services names to /etc/services. For example:
geofwd 50005/tcp # GeoTrac forwarded port(netcat)
3. Add service file to /etc/xinetd.d. Example file:
4. # default: on
# description: forward connections to panama:1005
service geofwd
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/bin/nc
server_args = 192.168.124.38 1005
log_on_failure += USERID
}

5. Restart xinetd
# /etc/rc.d/init.d/xinetd restart

SELECT accounts.id, mail.mail_name, accounts.password, domains.name FROM domains LEFT JOIN mail ON domains.id = mail.dom_id LEFT JOIN accounts ON mail.account_id = accounts.id

http://kb.parallels.com/en/1473 -> How to use tcpdump to catch xml-rpc requests sent from/to POA to/from external
systems
http://kb.parallels.com/en/2261 -> Clustered qmail tasks are stuck in running state forever, email services do not work
properly
http://kb.parallels.com/en/5476 -> LDAP server is not responding, database looks corrupted.
http://kb.parallels.com/en/1877 -> How do I test spamassasin delete or mark ability on qmail host?

Solution

This example will change the ethernet device with name dev12345 to eth0 and assumes eth0 currently does not exist.
Down the device before changing any files with the command # ifdown dev12345. Also remove the kernel module which is
referenced against this device in the /etc/modprobe.conf. In this example there is a line which has “alias dev12345
e1000
“, so perform “#rmmod e1000“. It may also be necessary to run “#ifdown ” on any other network devices using this
kernel module. If this step is skipped it may be necessary to undo any file name changes including setting up the
ifcfg-dev12345 file as mentioned below.
Modify the file /etc/sysconfig/hwconf replacing ifcfg-dev12345 with ifcfg-eth0. If this file doesn’t exist ignore this
step as this file is simply a generated file from the Red Hat Enterprise Linux installation program:
class: NETWORK
bus: PCI
detached: 0
device: eth0

Modify the file /etc/modprobe.conf replacing ifcfg-dev12345 with ifcfg-eth0:
alias eth0 e1000
In the directory /etc/sysconfig/network-scripts/ rename the file ifcfg-dev12345 to ifcfg-eth0. Edit this file replacing
ifcfg-dev12345 with ifcfg-eth0:
DEVICE=eth0
If the system-config-network* tools were used, it may be necessary to remove any file referencing the old device in the
/etc/sysconfig/networking directory. ie.
# find /etc/sysconfig/networking -name ifcfg-dev12345
/etc/sysconfig/networking/profiles/default/ifcfg-dev12345
/etc/sysconfig/networking/devices/ifcfg-dev12345
# rm /etc/sysconfig/networking/profiles/default/ifcfg-dev12345
# rm /etc/sysconfig/networking/devices/ifcfg-dev12345
At this stage it is now possible to up eth0 with the command # ifup eth0.

rpm -iv –replacepkgs httpd-2.2.3-5.i386.rpm

Ever want to immediatly serve content from a specific directory over HTTP, but didn’t want to bother messing with
httpd.conf or other webserver configiurations?

If you’ve got Python installed, this is a snap. Execute python with the SimpleHTTPServer module, using port 8080 so
there isn’t a need to elevate privs to root.

$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 …

or python3 -m http.server 8080

Sure enough, pointing a browser to the IP address :8080 of the box hits my home directory listing. Super easy, super
fast, super simple!

I use this to serve content to my PS3. The PS3 doesn’t support NFS or CIFS, so to download content to the hard drive,
the best method is by pulling it over HTTP with the embedded web brower. On my MacBook, I change into the directory
containing whatever media I want to transfer, fire up HTTP, and suck it down to the hard drive on the PS3. Nice!

source: http://prefetch.net/blog/index.php/2009/10/31/serve-out-content-over-http-from-your-cwd-immediatly/

c ~ $ strace -f -s 128 $(pidof httpd |sed 's/\([0-9]*\)/\-p \1/g')

Quite simple really, just use sed to make the necessary command line switches.

strace wants to have the PIDs passed one per '-p' switch. It would be nice to have a -p 3434,4565,4342 option but oh
well. sed with a easy replace handles all that's necessary.

Observe the output of pidof

c ~ $ pidof httpd
9629 9439 9428 9427 9426 9425 9424 9420

Wrap with sed to create multiple -p switches.

c ~ $ pidof httpd |sed 's/\([0-9]*\)/\-p \1/g'
-p 9629 -p 9439 -p 9428 -p 9427 -p 9426 -p 9425 -p 9424 -p 9420

Now combine with strace.

c ~ $ strace $(pidof httpd |sed 's/\([0-9]*\)/\-p \1/g')
carbon share # strace $(pidof apache2 |sed 's/\([0-9]*\)/\-p \1/g')
Process 9629 attached - interrupt to quit
Process 9439 attached - interrupt to quit
Process 9428 attached - interrupt to quit
Process 9427 attached - interrupt to quit
Process 9426 attached - interrupt to quit
Process 9425 attached - interrupt to quit
Process 9424 attached - interrupt to quit
Process 9420 attached - interrupt to quit
[pid 9439] semop(10846209, 0xb7bd9a28, 1
[pid 9629] semop(10846209, 0xb7bd9a28, 1
[pid 9428] epoll_wait(10,
[pid 9427] semop(10846209, 0xb7bd9a28, 1
[pid 9426] semop(10846209, 0xb7bd9a28, 1
[pid 9424] semop(10846209, 0xb7bd9a28, 1
[pid 9420] select(0, NULL, NULL, NULL, {0, 730000}
[pid 9425] semop(10846209, 0xb7bd9a28, 1
[pid 9420] <... select resumed> ) = 0 (Timeout)
[pid 9420] waitpid(-1, 0xbff91918, WNOHANG|WSTOPPED) = 0
[pid 9420] select(0, NULL, NULL, NULL, {1, 0}) = 0 (Timeout)

Now go debug some PHP or CGI application in the guts

Source: http://edoceo.com/exemplar/strace-multiple-processes