November 30, 2012

run as user in inittab or init

Sometimes sudo -u USERNAME gives error.

You can try to to use su USERNAME -c "COMMAND" instead.

November 28, 2012

Start screen after sudo su to another user


Sudo'ing to a user then running screen doesn't work out of the box.  Typically you get the following error:
Cannot open your terminal '/dev/pts/1' - please check.
The solution:
sudo su - someuser
script /dev/null
screen

Source: http://dbadump.blogspot.com/2009/04/start-screen-after-sudo-su-to-another.html 

November 26, 2012

Creating a self-signed certificate with ADT


http://help.adobe.com/en_US/air/build/WS5b3ccc516d4fbf351e63e3d118666ade46-7f74.html

You can use self-signed certificates to produce a valid AIR installation file. However, self-signed certificates only provide limited security assurances to your users. The authenticity of self-signed certificates cannot be verified. When a self-signed AIR file is installed, the publisher information is displayed to the user as Unknown. A certificate generated by ADT is valid for five years.
If you create an update for an AIR application that was signed with a self-generated certificate, you must use the same certificate to sign both the original and update AIR files. The certificates that ADT produces are always unique, even if the same parameters are used. Thus, if you want to self-sign updates with an ADT-generated certificate, preserve the original certificate in a safe location. In addition, you will be unable to produce an updated AIR file after the original ADT-generated certificate expires. (You can publish new applications with a different certificate, but not new versions of the same application.)
Important: Because of the limitations of self-signed certificates, Adobe strongly recommends using a commercial certificate issued by a reputable certification authority for signing publicly released AIR applications.
The certificate and associated private key generated by ADT are stored in a PKCS12-type keystore file. The password specified is set on the key itself, not the keystore.

Certificate generation examples

adt -certificate -cn SelfSign -ou QE -o "Example, Co" -c US 2048-RSA newcert.p12 39#wnetx3tl 
adt -certificate -cn ADigitalID 1024-RSA SigningCert.p12 39#wnetx3tl

To
use these certificates to sign AIR files, you use the following
signing options with the ADT -package or -prepare commands:

-storetype pkcs12 -keystore newcert.p12 -keypass 39#wnetx3tl 
-storetype pkcs12 -keystore SigningCert.p12 -keypass 39#wnetx3tl

Note: Java versions 1.5 and above do not accept high-ASCII characters in passwords used to protect PKCS12 certificate files. Use only regular ASCII characters in the password.


ADT -package command examples

Package specific application files in the current directory for a SWF-based AIR application:

adt –package -storetype pkcs12 -keystore cert.p12 myApp.air myApp.xml myApp.swf components.swc

November 10, 2012

netcat/ncat server file as a web server

I will use the ncat (part of nmap) tool:

1. first create a bash file with the following contents, and save it as nchttp.sh, and chmod+x on it:
#!/bin/sh
echo "HTTP/1.1 200 OK"
mydate=`date -R`
echo "Date: $mydate"
echo "Server: Apache"
echo "Last-Modified: $mydate"
echo "Accept-Ranges: bytes"
echo "Content-Disposition: inline; filename=\"$1\"";
mysize=`stat $1 |awk '/Size/{print $2}'`
echo "Content-Length: $mysize"
echo "Keep-Alive: timeout=30, max=300"
echo "Connection: Keep-Alive"
echo "Content-Type: application/octet-stream"
echo
cat $1

2. ./nchttp.sh the-file-to-be-downloaded | ncat -l -vv 8001

3. point your brower to your http://YOURSERVERIP:8001, your file will be downloaded

November 9, 2012

Faster ssh X11 Forwarding


I use ssh daily to connect to my servers and laptops around my home office. Most of the time I'm using ssh to login and build software, so it's plain and simple command line activity. However, sometimes I need to run an X11 application on a remote machine, in which case I use X forwarding to display the remote X application on my laptop. However, this can be slow. Today I stumbled on the following incantation to speed up X11 forwarding over ssh:


ssh -c arcfour,blowfish-cbc -X -C user@remotehost

Thanks to Samat Jain for this info.

The choice of cipher is based on some performance benchmarks as noted in LaunchPad bug #54180

Source: http://smackerelofopinion.blogspot.com/2009/07/faster-ssh-x11-forwarding.html

November 7, 2012

php mail() function data flow

php mail() called /usr/sbin/sendmail, which may be a symbolic link to exit4 or sendmail.postfix or whatever sendmail "MTA" installed on your system. If you change that to your own sendmail, you can probably log all outgoing emails for debugging purpose.

November 6, 2012

Build and install python and mercurial from scratch on a system


wget http://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
wget http://www.selenic.com/mercurial/release/mercurial-1.2.1.tar.gz
tar zxvf mercurial-1.2.1.tar.gz
tar zxvf Python-2.5.4.tgz

Configure and build Python using /opt - you could use /usr/local or similar but I preferred to keep it out of my $PATH:

cd Python-2.5.4
./configure --prefix=/opt
make
su -c "make install"

Test Python installed properly:

/opt/bin/python
Python 2.5.4 (r254:67916, Mar 25 2009, 12:16:36)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-56)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Build Mercurial, using your Python 2.5:

cd ../mercurial-1.2.1
su -c "make install PYTHON=/opt/bin/python PREFIX=/opt"

Test Mercurial installed properly:

/opt/bin/hg --version
Mercurial Distributed SCM (version 1.2.1)
Copyright (C) 2005-2009 Matt Mackall and others

You may wish to symlink hg from somewhere in your $PATH:
su -c "ln -s /opt/bin/hg /usr/local/bin/hg"

Obviously you'll need a C compiler and associated development tools installed. You may find that the Python configure command complains of missing libraries, such as zlib-devel which can be installed via yum if required

Source: http://blog.friedland.id.au/2009/03/installing-mercurial-on-rhelcentos-3.html

November 2, 2012

When running configure, “.infig.status: error: cannot find input file:” error was generated:


This appears to be caused by by having DOS style line endings in the configure script.
You should be able to use the dos2unix command or alternatively, the tr command:

$ tr -d "\15\32" < configure > configure.new
$ mv configure.new configure
     $ chmod +x configure

 Original Post Here

November 1, 2012

linux console get image size

On linux console, if you need to get an image size, and imagemagick is not installed, you can use the following script (save it as "getimgsize.php", chmod +x, then run it with your image file":


#!/usr/bin/php -f
<?php
if ($argc<2){
        die("Usage: getimagesize IMAGEFILE\n");
}
list($width, $height, $type, $attr) = getimagesize($argv[1]);
echo "Size is $width x $height\n";