25 Kasım 2013 Pazartesi

colrm - linux

echo "123456" | colrm -4

31 Ekim 2013 Perşembe

Sed - Boş satırları silmek

sed '/^$/d' input.txt > output.txt

22 Ekim 2013 Salı

Linux - tar.bz2 dosyasını açmak

tar jxf file.tar.bz2

30 Eylül 2013 Pazartesi

Unix - İki dosyanın ortak satırları

perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/'  file1 file2

30 Haziran 2013 Pazar

Raspberry - cgi dizini


./apache2/sites-available/default dosyasındadır.

Örnek:
./apache2/sites-available/default:      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

Sonuçta Raspbian da bir Debian dağıtımıdır.



Raspberry - Hostname değiştirmek

sudo vi /etc/hostname
sudo reboot
hostname --fqd

21 Haziran 2013 Cuma

Linux kabuk değişkenleri

$$ = The PID number of the process executing the shell.
$? = Exit status variable.
$0 = The name of the command you used to call a program.
$1 = The first argument on the command line.
$2 = The second argument on the command line.
$n = The nth argument on the command line.
$* = All the arguments on the command line.
$# The number of command line arguments.

Linux - Koşullar

There is a function provided by bash called test which returns a true or false value depending on the result of the tested expression. Its syntax is:

test expression

It can also be implied as follows:

[ expression ]

The tests below are test conditions provided by the shell:

-b file = True if the file exists and is block special file.
-c file = True if the file exists and is character special file.
-d file = True if the file exists and is a directory.
-e file = True if the file exists.
-f file = True if the file exists and is a regular file
-g file = True if the file exists and the set-group-id bit is set.
-k file = True if the files' "sticky" bit is set.
-L file = True if the file exists and is a symbolic link.
-p file = True if the file exists and is a named pipe.
-r file = True if the file exists and is readable.
-s file = True if the file exists and its size is greater than zero.
-s file = True if the file exists and is a socket.
-t fd = True if the file descriptor is opened on a terminal.
-u file = True if the file exists and its set-user-id bit is set.
-w file = True if the file exists and is writable.
-x file = True if the file exists and is executable.
-O file = True if the file exists and is owned by the effective user id.
-G file = True if the file exists and is owned by the effective group id.
file1 –nt file2 = True if file1 is newer, by modification date, than file2.
file1 ot file2 = True if file1 is older than file2.
file1 ef file2 = True if file1 and file2 have the same device and inode numbers.
-z string = True if the length of the string is 0.
-n string = True if the length of the string is non-zero.
string1 = string2 = True if the strings are equal.
string1 != string2 = True if the strings are not equal.
!expr = True if the expr evaluates to false.
expr1 –a expr2 = True if both expr1 and expr2 are true.
expr1 –o expr2 = True is either expr1 or expr2 is true.
The syntax is :

arg1 OP arg2



where OP is one of –eq, -ne, -lt, -le, -gt, or –ge. Arg1 and arg2 may be positive or negative integers or the special expression "-l string" which evaluates to the length of string.

Unix shell scripting - Log yazma fonsiyonu


Log-function

In a private message, I was asked how the log-function worked that I described above. Since this might be helpful to other people too, I'm answering the question in public.

First of all, I use Bash, don't know if this trick works in other Shells.

Content of script:


Code:
#!/bin/bash
. lib/functions.conf # mind the SPACE between the DOT and the path/filename!!! 
logfile=scheduler.log
func_eventlog "STARTING ABG JOB"
-=script runs some more, but that's irrelevant, the example is clear=-

Content of file: lib/functions.conf which by the way is executable :


Code:
################################################
#                                              #
# Log functie                                  #
#                                              #
# Usage:                                       #
#                                              #
# func_eventlog "Dit wil ik loggen"            #
#                                              #
# Variabelen:                                  #
#                                              #
# $logfile (logfile inclusief pad)             #
#                                              #
################################################

func_eventlog()
{
 echo -e "`date` - $1" >> $logfile
}

So whenever I want something logged, I just use:

func_eventlog "Send this text to logfile"

and I never ever have to worry about accidentally overwriting my logs instead of appending to them. 

14 Haziran 2013 Cuma

Awk - Boş satırları silmek

awk /./ dosya.txt

11 Haziran 2013 Salı

Ramlog - Raspberry Pi


SD CARD

An SD Card has a limited lifetime, it depends on various factors. Normally the lifetime declared by manufacturers is very long, but I have experienced that sometimes the lifetime is very short. °v°.

So taking care of the healt status of the SD CARDs could lead to a high reliability.

One of the factors that could broke your SD Card is the write cycles. As said, this number is normally very high but you cannot say if your SD CARD will have a behaviur in the average or under the average. So you can think to reduce the number of writes.

 

 



The /var/log directory contains the log files for your services and these files are often updated, if you have a lot of services running you have a lot of writes on your SD CARD, if the log files are not essential in your system you can move them on a RAM disk and then you can backup them when you want.

In my production system I'm using a tool that does the job: Ramlog.

"Ramlog act as a system daemon. On startup it creates ramdisk, it copies files from /var/log into ramdisk and mounts ramdisk as /var/log. All logs after that will be updated on ramdisk. Logs on harddrive are kept in folder /var/log.hdd which is updated when ramlog is restarted or stopped. On shutdown it saves log files back to harddisk so logs are consistent. Ramlog 2.x is using tmpfs by default, ramfs and kernel ramdisk are suppored as well. Program rsync is used for log synchronization."

To install Ramlog on your Raspbian system run the following instructions:

# sudo apt-get install lsof

# wget http://www.tremende.com/ramlog/download/ramlog-2.0.0.tar.gz

# cp -a ramlog /etc/init.d/ramlog

# cp -a ramlog.8.gz /usr/share/man/man8/ramlog.8.gz

# cp -a ramlog.cron /etc/cron.daily    #or to other dir based on your need

# cp -a ramlog.logrotate /etc/logrotate.d/ramlog

# cp -a ramlog.conf /etc/default/ramlog

 

With your favourite editor, edit the file /etc/default/ramlog and set the value for your RAM filesystem, for example TMPFS_RAMFS_SIZE=20 means you want to use 20 mega bytes of RAM.

You can retrieve the actual size for /var/log directory issueing the following command:

# ramlog getlogsize

 

Last, reboot your system

# sudo reboot -n

 



















24 Mayıs 2013 Cuma

JBoss - Data source parolalarını şifrelemek

JBOSS_HOME dizinininde şifre için encryption yapılır:


java -cp client/jboss-logging-spi.jar:lib/jbosssx.jar org.jboss.resource.security.SecureIdentityLoginModule <PASSWORD>


data source dosyasında tanımlanan security domain:


<?xml version="1.0" encoding="UTF-8"?>
<datasources>
    <local-tx-datasource>
        <jndi-name>PostgresDS</jndi-name>
        <connection-url>jdbc:postgresql://127.0.0.1:5432/test?protocolVersion=2</connection-url>
        <driver-class>org.postgresql.Driver</driver-class>
        <min-pool-size>1</min-pool-size>
        <max-pool-size>20</max-pool-size>

        <!-- REPLACED WITH security-domain BELOW
        <user-name>admin</user-name>
        <password>password</password>
        -->

        <security-domain>EncryptDBPassword</security-domain>

        <metadata>
            <type-mapping>PostgreSQL 8.0</type-mapping>
        </metadata>
    </local-tx-datasource>
</datasources>
 
 
JBOSS_HOME/server/server_adı/conf/login/login-config.xml dosyasında, ilgili security-domain'e ait otantikasyon bilgileri eklenir:



<application-policy name = "EncryptedHsqlDbRealm">
   <authentication>
      <login-module code = "org.jboss.resource.security.JaasSecurityDomainIdentityLoginModule"
       flag = "required">
          <module-option name = "username">sa</module-option>
          <module-option name = "password">E5gtGMKcXPP</module-option>
          <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=DefaultDS</module-option>
          <module-option name = "jaasSecurityDomain">jboss.security:service=JaasSecurityDomain,domain=ServerMasterPassword</module-option>
       </login-module>
    </authentication>
 </application-policy>


önceden üretilen şifre, buradaki password alanına girilmelidir.

JBoss restart'ı ile değişiklikler aktive olur.

23 Mayıs 2013 Perşembe

Solaris - IP konfigürasyonunu görüntülemek

/usr/sbin/ifconfig -a

Solaris - Tar

tar czf name_of_archive_file.tar.gz name_of_directory_to_tar
tar xzf name_of_archive_file.tar.gz name_of_directory_to_tar

Cacerts dosyasına yeni sertifika eklemek

To add a certificate to the cacerts store


  1. At a command prompt that is set to your JDK's jdk\jre\lib\security folder, run the following to see what certificates are installed:
    keytool -list -keystore cacerts
    You'll be prompted for the store password. The default password is changeit. (If you want to change the password, see the keytool documentation at http://docs.oracle.com/javase/1.4.2/docs/tooldocs/solaris/keytool.html.) This example assumes that the certificate with MD5 fingerprint 67:CB:9D:C0:13:24:8A:82:9B:B2:17:1E:D1:1B:EC:D4 is not listed, and that you want to import it (this particular certificate is needed by the Twilio API service).
  2. Obtain the certificate from the list of certificates listed at GeoTrust Root Certificates. Right-click the link for the certificate with serial number 35:DE:F4:CF and save it to the jdk\jre\lib\security folder. For purposes of this example, it was saved to a file named Equifax_Secure_Certificate_Authority.cer.
  3. Import the certificate via the following command:
    keytool -keystore cacerts -importcert -alias equifaxsecureca -file Equifax_Secure_Certificate_Authority.cer
    When prompted to trust this certificate, if the certificate has MD5 fingerprint 67:CB:9D:C0:13:24:8A:82:9B:B2:17:1E:D1:1B:EC:D4, respond by typing y.
  4. Run the following command to ensure the CA certificate has been successfully imported:
    keytool -list -keystore cacerts
  5. Zip the JDK and add it to your Windows Azure project's approot folder.

For information about keytool, see http://docs.oracle.com/javase/1.4.2/docs/tooldocs/solaris/keytool.html.

22 Mayıs 2013 Çarşamba

Linux - Proxy ayarları

http://www.cyberciti.biz/faq/linux-unix-set-proxy-environment-variable/

SVN - revizyon numarasına güncellemek

svn up -r 2147 config.java

Awk - linux swap colunms

awk 'BEGIN {FS=OFS=":"} {temp=$1; $1=$2; $2=temp} {print}' input.txt

10 Mayıs 2013 Cuma

Powershell - alt dizinlerde .svn dizinlerinden kurtulmak

powershell
gci -fil '.svn' -r -force | ri -r -force

10 Nisan 2013 Çarşamba

Windows'ta komut satırından Proxy etkisizleştirme

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ProxyEnable"=dword:00000000

Windows'ta komut satırından Proxy etkinleştirme

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ProxyEnable"=dword:00000001
"ProxyServer"="10.12.20.230:8080"
"ProxyOverride"="192.168.*;10.*"

9 Nisan 2013 Salı

Ant - mkdir

   
    <target name="create-folders">
        <mkdir dir="${build.folder}" />       
    </target>

Ant - Delete, dizin silme

    <target name="clean-folders">
        <delete dir="${silinecekdizin}" includeemptydirs="true" />       
    </target>

Ant - antcall

<target name="dummy">
    <antcall target="compile" />
</target>
   

Ant - lokale scp

<target name="dummy">        <scp keyfile="${keyfile.location}" file="user@hostname:/data/allatori_opdir/ObfuscationTest/app-jar-out/*" trust="true" failonerror="false"
            todir="/data/tarTemp/app-jars" >
            <fileset>
              <include name="*"/>
            </fileset>
        </scp>           
</target>
   

Ant - Lokalden scp

<target name="dummy">
   <scp keyfile="${keyfile.location}" trust="true" failonerror="false"
        todir="${app.server.user}@${app.server.ip}:${cms.folder.dest}/${page.postfix}" >
        <fileset dir="${temp.deploy.dir}/${backup.page.dir}">
          <include name="*"/>
        </fileset>
    </scp>
</target>

Ant - sshexec

    <sshexec host="${app.server.ip}"
                username="${app.server.user}"
                keyfile="${keyfile.location}"
                command="${jboss.stop.cmd}"
                timeout="20000"
                trust="true"
                failonerror="false"  />   

8 Nisan 2013 Pazartesi

Grep alfanümerik içeren satırlar

grep -Ei '[[:alnum:]]'

7 Nisan 2013 Pazar

aliaslar

http://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html

Unix - Grep'te grepi almamak

http://www.cyberciti.biz/tips/grepping-ps-output-without-getting-grep.html

AWK - Sonraki her n satırı birleştir

awk '{printf("%s%s", $0, (NR%3 ? "," : "\n"))}' details.txt

4 Nisan 2013 Perşembe

Raspberry - Boot'ta ssh'ı açmak

ssh'ı kurmak
sudo apt-get install ssh


ssh dinlemeye başlamak
sudo /etc/init.d/ssh start


tek sefere mahsus boot ile dinlemeyi öğretmek

sudo update-rc.d ssh defaults

 
reboot
sudo reboot

Raspberry - Network bilgileri

/sbin/ifconfig

3 Nisan 2013 Çarşamba

Svn mkdir - Repository üzerinde komut satırından dizin oluşturma

svn mkdir https://svn.cs.com.tr/svn/release/ALFA/ --parents --editor-cmd vi

2 Nisan 2013 Salı

Raspberry - SD boot sürücüsü oluşturmak / yedeklemek

http://raspberrypi.stackexchange.com/questions/311/how-do-i-backup-my-raspberry-pi

Java cacerts sertifikasının görüntülenmesi

C:\j2sdk1.4.2_04\jre\bin>keytool -list -keystore ./cacerts
Enter keystore password:  changeit
 
(default şifre: changeit)

30 Mart 2013 Cumartesi

28 Mart 2013 Perşembe

Raspbian - Sistem dilini değiştirmek

sudo dpkg-reconfigure locales

Raspbian - Klavye dilini değiştirmek

sudo vi /etc/default/keyboard

Raspbian - VNC'yi boot ile başlatmak

Start VNC Server Automatically on Bootup

There's no point in having VNC if you have goto to the Pi, login and start the server manually. So let's start it on bootup before the login prompt.
Create a new file in the init.d directory:
sudo nano /etc/init.d/tightvncserver
Enter the following details:
#!/bin/sh
# /etc/init.d/tightvncserver
VNCUSER='pi'
case "$1" in
    start)
        su $VNCUSER -c '/usr/bin/tightvncserver :1'
        echo "Starting TightVNC Server for $VNCUSER "
        ;;
    stop)
        pkill Xtightvnc
        echo "TightVNC Server stopped"
        ;;
    *)
        echo "Usage: /etc/init.d/tightvncserver {start|stop}"
        exit 1
        ;;
esac
exit 0
Give the script executable permission:
sudo chmod 755 /etc/init.d/tightvncserver
We can now start or stop the service manually:
sudo /etc/init.d/tightvncserver start
sudo /etc/init.d/tightvncserver stop
But let's make Tight VNC Server start every time the Raspberry Pi starts up:
sudo update-rc.d tightvncserver defaults
Now just power off the Raspberry Pi. Make sure it's connected to the network and power back on. You can now connected across the network using the VNC Viewer!


http://www.neil-black.co.uk/raspberry-pi-beginners-guide#.UVyuTjdvC9o

25 Mart 2013 Pazartesi

Debian - Bağlı paketlerle birlikte kurmak

sudo apt-get build-dep python-scipy --fix-missing

21 Mart 2013 Perşembe

Unix - dosya encoding öğrenme

file -bi test.txt

19 Mart 2013 Salı

Websphere - Wsadmin ile uygulama update

./wsadmin.sh -c "\$AdminApp update MyApp app \"-operation update -contents /home/MyApp.war -usedefaultbindings\" "

Ant - Escape characters

For > use &gt; For < use  &lt;
For use &quot;
For & use &amp;
For use &apos;

28 Şubat 2013 Perşembe

Distro öğrenme

cat /etc/issue

21 Şubat 2013 Perşembe

Command line before login - Windows 7

Left Alt + Left Shift + PrintScreen