(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
A big part of our jobs requires some Shell Script knowledge. The Blog main goal is help anyone with scripts problems and doubts. Occasionally, anyone can send tips to the Blog that might help our every-day tasks.
Friday, January 28, 2011
Thursday, January 27, 2011
One line webserver
$ python -m SimpleHTTPServer
Muito útil para testes ou compartilhamento rápido de arquivos.
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)
Where c=7 is the number of lines you want to grep after.
# 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):
2 –
3 –
Linux (by Gux):
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:
Simple and working, maybe it is useful for you all.
#!/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.
.bash_profile and .bashrc differences
In this article the author explains the differences between login shells, interactive shells and non-interactive shells:
http://hacktux.com/bash/bashrc/bash_profile
http://hacktux.com/bash/bashrc/bash_profile
Inserting characters in the middle of a string
Recently I had a problem to solve that involved inserting a byte in the middle of a line, and it was 522K lines :(.
Sometime ago I saw a video from Aurélio that teaches how to accomplish that: http://vimeo.com/11744241
But you don't have to watch the video (its in portuguese). The simple way is using sed:
We will seach for anything ('s), change this anything to itself plus a new byte ('s/./&39) and say on which position ('s/./&39 /3):
With almost the same code, we could change the 3rd character to something else:
Sometime ago I saw a video from Aurélio that teaches how to accomplish that: http://vimeo.com/11744241
But you don't have to watch the video (its in portuguese). The simple way is using sed:
We will seach for anything ('s), change this anything to itself plus a new byte ('s/./&39) and say on which position ('s/./&39 /3):
$ echo "#####" |sed 's/./&39 /3'
###39 ##
With almost the same code, we could change the 3rd character to something else:
$ echo "#####" |sed 's/./3/3'
##3##
Tuesday, January 25, 2011
Remove distinct line with sed
sed '4d;7d' file.txt
This will remove lines 4 and 7 from file.txt
sed '4,7d' file.txt
But this is a range, so will remove lines from 4 to 7 from file.txt
Subscribe to:
Posts (Atom)