1. Sed
Sed adalah stream editor. Pada dasarnya digunakan untuk manipulasi text.
Perintah dasar.
sed [-lrn] [-e 'sedscript'] [file1 file2 ...]
-l : line buffered
-r : extended regex
-n silences default output
Paling males kan baca perintah dasar? soalnya saya blm paham kalau ngga ada contohnya :P.
% echo "Hello there foo" | sed -e 's/foo/bar/'
Hello there bar
nah.. paham kan? perintah diatas dpt digunakan untuk mereplace foo menjadi bar
saya mencoba perintah berikut dan berhasil
# more limit | sed -e 's/fxp1/rl0/' >> limitbaru
perintah diatas adalah membaca file dgn nama limit dan mereplace semua kata yg mengandung fxp1 menjadi rl0 dan hasilnya disimpan dalam file limitbaru
Perintah sed juga bisa berfungsi seperti grep.
% sed -ne '/FreeBSD/p' /etc/motd
FreeBSD 6.2-PRERELEASE (FOO) #0: Sat Nov 11 00:12:52 EST 2006
Welcome to FreeBSD!
Dapat digunakan juga untuk melihat header mail.
% cat mymail \
| sed -ne '/^[A-Za-z0-9]/ { x; /^Received: /{p;}; }; /^[A-Za-z0-9]/!H'
Received: from localhost (localhost [127.0.0.1])
by whitefox.csh.rit.edu (Postfix) with ESMTP id 731F81145C
for
Received: from whitefox.csh.rit.edu ([127.0.0.1])
by localhost (whitefox.csh.rit.edu [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id EURHKUeHSrao for
Sat, 19 May 2007 01:19:16 -0400 (EDT)
2. cut
Cut digunakan untuk memotong bbrp bagian dr data.
Perintah dasar
cut [-d delim -f range] [-c range] [-b range]
% echo "one,two,three,four" | cut -d"," -f 1,3
one,three
yang tdk bisa dieksekusi oleh cut
% echo "one two three" | cut -d' ' -f 2
% echo "one two three" | awk '{print $2}'
two
3. awk
awk merupakan filter tool pada scripting
Perintah dasar
awk [-F
awk mempunyai 2 konsep data spyt pd input file yaitu field dan record
record adalah seluruh baris, pemisah antar record adl baris baru
field adalah kata2, pemisahnya adalah spasi atau tab. default pemisahnya adalah spasi tapi bs juga sebuah karakter atau regular expression.
pattern : [condition_expressions] { [action_expressions] }
% fstat | sed -e 1d \
| awk '{a[$1]++} END { for (i in a) { print i, a[i] } }' \
| sort -nk2
smmsp 8
_dhcp 11
www 45
root 328
jls 482
Show file yg tdk kosong
% ls -l | awk '$5 > 0'
Show log antar 10 May dan 20 May
% cat *.log | awk '$1 == "May" && ($2 >= 10 && $2 <= 20)'
Show ip dari perintah host
% host www.google.com | awk '/has address/ { print $4 }'
Sulit sekali memahami perintah awk ini..
Tapi emang powerfull bgt..
4. xarg
xarg digunakan untuk mengambil argumen dan digunakan untuk menjalakan program.
Perintah dasar
xargs [flags] [command [args]]
# delete png file
% find ./i/ -name '*.png' | xargs rm
% cat /tmp/somehosts \
| xargs -P10 -I"HOST" -n1 sh -c 'ssh HOST uptime | sed -e "s/^/HOST: /"'
Tiba2 koq laper.. :(
Sampe sini aja dulu...
Taken : semicomplete.com
Mengenal beberapa Unix tool.
cara reset mikrotik
hardware | Tuesday, November 03, 2009
Teman2 sempat pusing mikirin ada perangkat mikrotik warisan tapi lupa passwordnya. Dari googling ada cara ribet yaitu install ulang OS nya via kabel dan butuh software ini itu [lupa].
Tapi hal itu takkan pernah terjadi setelah nemu postingan di forum berikut :
look above: this little hole is JP1, Stick a screwdriver in it while booting (to short-circuit it) and it will reset the config.
thx a lot to http://forum.mikrotik.com
Cara eksport dan import database mysql di unix based
database | Thursday, October 29, 2009
Cara untuk eksport database mysql via console bisa dilakukan sbb :
# mysqldump -uusernya -ppasswordnya master > backup.sql
Perintah diatas akan melakukan export data pada database master kedalam file backup.sql
Sedangkan cara untuk import database sbb:
# mysqldump -uusernya -ppasswordnya dbbaru backup.sql
Namun jika database yang di import besar ratusan MB dpt digunakan cara sbb :
# mysql -u root -p
# use dbbaru;
# source /home/aku/backup.sql
Yatta!!.. berhasil.. berhasil.. alhamdulillah...moga2 saja bisa untuk backup database sampe satu GB huehue..
upgrade Freebsd dari release ke stable dengan cvsup
| Wednesday, October 28, 2009
Berikut langkah2 untuk upgrade Freebsd stable
# whereis cvsup-without-gui
cvsup-without-gui: /usr/ports/net/cvsup-without-gui
# cd /usr/ports/net/cvsup-without-gui
# make install clean
Setelah selesai copy kedua file cvsup ke directory /etc
#cp /usr/share/examples/cvsup/ports-supfile /etc
#cp /usr/share/examples/cvsup/stable-supfile /etc
Edit kedua file tsb dan pada baris
default host=
isi dengan cvsup.freebsd.or.id atau cari server cvsup terdekat
kemudian jalankan perintah
# cd /etc
# cvsup -g -L 2 ports-supfile && cvsup -g -L 2 stable-supfile
# cd /usr/src
# make buildworld
# make buildkernel KERNCONF=namakernel
# make installkernel KERNCONF=namakernel
# shutdown -r now (untuk reboot)
# cd /usr/src
# make installworld
# uname -a
FreeBSD ns1.xxx.xxx.id 7.2-STABLE FreeBSD 7.2-STABLE #0: Wed Oct 28 09:58:36 UTC 2009 ainur@xxx.xxx.id
install apache 22 + SSL
| Tuesday, September 08, 2009
# cd /usr/ports/www/apache22
# make install clean
# mkdir /usr/local/etc/apache22/ssl.key
# mkdir /usr/local/etc/apache22/ssl.crt
# chmod 0700 /usr/local/etc/apache22/ssl.key
# chmod 0700 /usr/local/etc/apache22/ssl.crt
# cd /root
# openssl genrsa -des3 -out server.key 1024
# openssl req -new -key server.key -out server.csr
# openssl x509 -req -days 365 -in /root/server.csr -signkey /root/server.key -out /root/server.crt
# cp /root/server.key /usr/local/etc/apache22/ssl.key/
# cp /root/server.crt /usr/local/etc/apache22/ssl.crt/
# chmod 0400 /usr/local/etc/apache22/ssl.key/server.key
# chmod 0400 /usr/local/etc/apache22/ssl.crt/server.crt
# cd /usr/local/etc/apache22/extra
# vi httpd-ssl.conf
Isikan httpd-ssl.conf sbb :
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
# Pass Phrase Dialog:
# Configure the pass phrase gathering process.
# The filtering dialog program (`builtin' is a internal
# terminal dialog) has to provide the pass phrase on stdout.
SSLPassPhraseDialog builtin
# Inter-Process Session Cache:
# Configure the SSL Session Cache: First the mechanism
# to use and second the expiring timeout (in seconds).
#SSLSessionCache "dbm:/var/run/ssl_scache"
SSLSessionCache "shmcb:/var/run/ssl_scache(512000)"
SSLSessionCacheTimeout 300
# Semaphore:
# Configure the path to the mutual exclusion semaphore the
# SSL engine uses internally for inter-process synchronization.
SSLMutex "file:/var/run/ssl_mutex"
##
## SSL Virtual Host Context
##
# General setup for the virtual host
DocumentRoot "/usr/local/www/apache22/data"
ServerName www.example.com:443
ServerAdmin you@example.com
ErrorLog "/var/log/httpd-error.log"
TransferLog "/var/log/httpd-access.log"
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. Keep
# in mind that if you have both an RSA and a DSA certificate you
# can configure both in parallel (to also allow the use of DSA
# ciphers, etc.)
SSLCertificateFile "/usr/local/etc/apache22/ssl.crt/server.crt"
#SSLCertificateFile "/usr/local/etc/apache22/server-dsa.crt"
# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile "/usr/local/etc/apache22/ssl.key/server.key"
#SSLCertificateKeyFile "/usr/local/etc/apache22/server-dsa.key"
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
#SSLCertificateChainFile "/usr/local/etc/apache22/server-ca.crt"
# Certificate Authority (CA):
# Set the CA certificate verification path where to find CA
# certificates for client authentication or alternatively one
# huge file containing all of them (file must be PEM encoded)
# Note: Inside SSLCACertificatePath you need hash symlinks
# to point to the certificate files. Use the provided
# Makefile to update the hash symlinks after changes.
#SSLCACertificatePath "/usr/local/etc/apache22/ssl.crt"
#SSLCACertificateFile "/usr/local/etc/apache22/ssl.crt/ca-bundle.crt"
SSLOptions +StdEnvVars
SSLOptions +StdEnvVars
BrowserMatch ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# Per-Server Logging:
# The home of a custom SSL log file. Use this when you want a
# compact non-error SSL logfile on a virtual host basis.
CustomLog "/var/log/httpd-ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
Supaya tiap kali start apache tdk ditanya password, lakukan sbb :
cd /usr/local/etc/apache22/ssl.key/
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
