Friday, January 28, 2011

How to convert SSH keypairs generated using PuttyGen(Windows) into key-pairs used by ssh-agent and KeyChain(Linux)

(Via http://stackoverflow.com/questions/2224066/how-to-convert-ssh-keypairs-generated-using-puttygenwindows-into-key-pairs-used)

puttygen supports exporting to an OpenSSH compatible format.

1. Open PuttyGen
2. Click Load
3. Load your private key
4. Go to Conversions->Export OpenSSH and export your private key
5. Copy your private key to ~/.ssh/id_dsa (or id_rsa).
6. Create the RFC 4716 version of the public key using ssh-keygen

ssh-keygen -e -f ~/.ssh/id_dsa > ~/.ssh/id_dsa_com.pub

7. Convert the RFC 4716 version of the public key to the OpenSSH format:

ssh-keygen -i -f ~/.ssh/id_dsa_com.pub > ~/.ssh/id_dsa.pub

Thursday, January 27, 2011

One line webserver

$ python -m SimpleHTTPServer

Muito útil para testes ou compartilhamento rápido de arquivos.

CPU utilization of multi process program

(Via Emerson Gomes at Gemalto)

for a in FRWK RCA SAS GCCM GCDM GCDT;
do
total=0; echo -ne `/usr/ucb/ps auxww | egrep \($a\) | awk '{print $3}' | while read i; do total=$(echo "$total + $i" | bc); echo $total; done | tail -1` \ ;
done

sed emulating Unix commands

(Via http://sed.sourceforge.net/local/docs/emulating_unix.txt)


SED emulating UNIX commands by Aurelio Jargas
--------------------------- www.aurelio.net/en
verde at aurelio.net


Here's the list of some UNIX commands that can be emulated
using SED. Please, if know about others, contribute!


UNIX | SED
-------------+----------------------------------------------------------------
cat | sed ':'
cat -s | sed '1s/^$//p;/./,/^$/!d'
tac | sed '1!G;h;$!d'
grep | sed '/patt/!d'
grep -v | sed '/patt/d'
head | sed '10q'
head -1 | sed 'q'
tail | sed -e ':a' -e '$q;N;11,$D;ba'
tail -1 | sed '$!d'
tail -f | sed -u '/./!d'
cut -c 10 | sed 's/\(.\)\{10\}.*/\1/'
cut -d: -f4 | sed 's/\(\([^:]*\):\)\{4\}.*/\2/'
tr A-Z a-z | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
tr a-z A-Z | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
tr -s ' ' | sed 's/ \+/ /g'
tr -d '\012' | sed 'H;$!d;g;s/\n//g'
wc -l | sed -n '$='
uniq | sed 'N;/^\(.*\)\n\1$/!P;D'
rev | sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'
basename | sed 's,.*/,,'
dirname | sed 's,[^/]*$,,'
xargs | sed -e ':a' -e '$!N;s/\n/ /;ta'
paste -sd: | sed -e ':a' -e '$!N;s/\n/:/;ta'
cat -n | sed '=' | sed '$!N;s/\n/ /'
grep -n | sed -n '/patt/{=;p;}' | sed '$!N;s/\n/:/'
cp orig new | sed 'w new' orig
hostname -s | hostname | sed 's/\..*//'


To be reworked:

echo 'Hi!' | sed 's/.*/Hi!/;q' <(yes)


NOTE: On MSDOS, use " instead '


-------------------------------------------------------------------------------

THANK YOU to:
- Adam Peresztegi (Hungary)
- Eric De Mund (USA)
- Eric Pement and his "Sed 1liners" document
- Don (Australia)
- Thobias Salazar Trevisan (Brazil)
- The sed-users@yahoogroups.com mailing list

grep -A for Solaris

(Via Edson Oliveira at Gemalto)

# nawk '/root/{c=7}c&&c--' /etc/passwd


Where c=7 is the number of lines you want to grep after.

df format problems

Sometimes when you get a df from Linux or Solaris, the device appears in on line, and the rest of the information on other line. Here’s a tip to avoid this:

Solaris:

1 – (http://unixsadm.blogspot.com/2008/05/custom-df-diskfree-column-output-in.html):

# df -g | nawk '{if (NR % 5 == 1) printf "%-22s", $1 ; if (NR % 5 == 4) printf "%-10s", "fstype " $1 "\n"; if (NR % 5 == 2) printf "%-30s",$1/2/1024/1024 " GB"; if (NR % 5 == 2) printf "%-30s", $4/2/1024/1024 " GB free "}'


2 –

# printf "%s\n" "$(df -k)"


3 –
# ${__?"$(df -k)"}


Linux (by Gux):

# df -P | column -t

Get pid from a specific port in solaris

(Via Gonzalo Barrio at Gemalto) Hi all, I used to do a netstat -lntp in Linux to get the process id binded to some port and this doesn't work on Solaris. So I googled and found the following script:


#!/bin/ksh

line='---------------------------------------------'
pids=$(/usr/bin/ps -ef | sed 1d | awk '{print $2}')

if [ $# -eq 0 ]; then
read ans?"Enter port you would like to know pid for: "
else
ans=$1
fi

for f in $pids
do
/usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $ans"
if [ $? -eq 0 ]; then
echo $line
echo "Port: $ans is being used by PID:\c"
/usr/bin/ps -ef -o pid -o args | egrep -v "grep|pfiles" | grep $f
fi
done
exit 0


Simple and working, maybe it is useful for you all.