Livestreamer ile Youtube

Şubat 10, 2014 § Yorum yok § Kalıcı bağlantı

livestreamer kuralım:

$ sudo yum install python-pip
$ sudo pip install livestreamer 

livestreamer ile Youtube izlemek için

livestreamer http://www.youtube.com/watch?v=U4Pw3ofFWgs best
veya
livestreamer --player=mplayer http://www.youtube.com/watch?v=U4Pw3ofFWgs 360p 

Birçok processi öldürme

Şubat 10, 2014 § Yorum yok § Kalıcı bağlantı

Önce grep dosru sonuç veriyor mu kontrol edelim:

ps aux | grep jppf

xmodulo   3324  0.1  2.9 156524 15176 pts/0    Sl   22:16   0:01 /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/bin/java -Xmx32m -Djppf.config=jppf-driver.properties -Dlog4j.configuration=log4j-driver.properties -Djava.util.logging.config.file=config/logging-driver.properties -classpath /home/xmodulo/JPPF-3.2.2-driver/config:/home/xmodulo/JPPF-3.2.2-driver/lib/jmxremote_optional.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/jppf-common-node.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/jppf-common.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/jppf-server.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/log4j-1.2.15.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/slf4j-api-1.6.1.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/slf4j-log4j12-1.6.1.jar org.jppf.server.DriverLauncher
xmodulo   3338  0.3  4.4 391484 22792 pts/0    Sl   22:16   0:03 /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/bin/java -cp /home/xmodulo/JPPF-3.2.2-driver/config:/home/xmodulo/JPPF-3.2.2-driver/lib/jmxremote_optional.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/jppf-common-node.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/jppf-common.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/jppf-server.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/log4j-1.2.15.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/slf4j-api-1.6.1.jar:/home/xmodulo/JPPF-3.2.2-driver/lib/slf4j-log4j12-1.6.1.jar -Djppf.config=jppf-driver.properties -Dlog4j.configuration=log4j-driver.properties -Xmx256m -Djava.util.logging.config.file=config/logging-driver.properties org.jppf.server.JPPFDriver 59216
xmodulo   3388  0.1  2.9 139144 15064 pts/0    Sl   22:19   0:01 /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/bin/java -Xmx16m -Dlog4j.configuration=log4j-node.properties -Djppf.config=jppf-node.properties -Djava.util.logging.config.file=config/logging-node.properties -classpath /home/xmodulo/JPPF-3.2.2-node/config:/home/xmodulo/JPPF-3.2.2-node/lib/jmxremote_optional.jar:/home/xmodulo/JPPF-3.2.2-node/lib/jppf-common-node.jar:/home/xmodulo/JPPF-3.2.2-node/lib/log4j-1.2.15.jar:/home/xmodulo/JPPF-3.2.2-node/lib/slf4j-api-1.6.1.jar:/home/xmodulo/JPPF-3.2.2-node/lib/slf4j-log4j12-1.6.1.jar org.jppf.node.NodeLauncher
xmodulo   3402  0.1  3.9 257980 20288 pts/0    Sl   22:19   0:01 /usr/lib/jvm/java-1.6.0-

Birçok processi grep ile ayıklayıp öldürmek için:

kill -9 `ps aux | grep <keyword> | awk '{print $2}'` 

Dosya isimlerine tarih eklemek

Şubat 10, 2014 § Yorum yok § Kalıcı bağlantı


now=$(date +"%Y-%m-%d-%S")
filename="my_program.$now.log"
# example filename: my_program.2012-01-23-47.log

nanosecond seviyesinde zaman için:

now=$(date +"%Y.%m.%d.%S.%N")
filename="my_program.$now.log"
# example filename: my_program.2013.01.23.44.364617000.log

epoch olarak zaman:

now=$(date +"%s")
filename="my_program.$now.log"
# example filename: my_program.1358995092.log

Dosya sahipliklerini ve izinlerini koruyarak taşımak

Ocak 15, 2014 § Yorum yok § Kalıcı bağlantı

rsync komutunun -a parametresi ile kullanımı bu iş için uygun görünüyor.
Not1: -a kullanılmadığında izinler korunmamaktadir.
Not2: -a kullanıldığında recursive için -r’ye ihtiyaç yoktur. -a zaten recursivedir.
Genel olarak parametreler:
-v : verbose
-r : recursive copyalama sağlar fakat izinler korunmaz
-a : arşiv modu. Recursive çalışır ve izinleri, sahiplikleri vs korur
-z : dosyaları sıkıştırarak gönderir
-h : human-readable formatta çıktı verir
Örnek:

[root@fatihoz ~]# rsync -azvh --progress /home/fatih/1G.file  /tmp/
sending incremental file list
1G.file
       1.02G 100%   38.46MB/s    0:00:25 (xfer#1, to-check=0/1)

sent 995.86K bytes  received 31 bytes  33.76K bytes/sec
total size is 1.02G  speedup is 1028.22
[root@fatihoz ~]# ls -l /tmp/1G.file 
-rw-rw-r--. 1 fatih fatih 1024000000 Jan 15 05:59 /tmp/1G.file

Not3:recursive kopyalama da eğer dizinide kopyalamak istiyorsak dizin adından sonra “/” konmamalıdır.

Dizin içeriğini taşımak için:

[root@fatihoz ~]# rsync -azvh --progress deneme/  /tmp/
sending incremental file list
./
1.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=3/5)
12233434543.txt
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=2/5)
122343.txt
           0 100%    0.00kB/s    0:00:00 (xfer#3, to-check=1/5)
123.txt
           0 100%    0.00kB/s    0:00:00 (xfer#4, to-check=0/5)

sent 246 bytes  received 91 bytes  674.00 bytes/sec
total size is 0  speedup is 0.00
[root@fatihoz ~]# ls /tmp/
12233434543.txt       .ICE-unix/            .vbox-root-ipc/
122343.txt            keyring-laEwp7/       virtual-fatih.1zDlF2/
123.txt               orbit-fatih/          virtual-fatih.VRdNGR/
1G.file               orbit-gdm/            virtual-fatih.XuZfls/
1.txt                 pulse-Z1C3D8mISpLD/   .X0-lock
.esd-500/             .vbox-fatih-ipc/      .X11-unix/

Dizini de taşımak için

 
[root@fatihoz ~]# rsync -azvh --progress deneme  /tmp/
sending incremental file list
deneme/
deneme/1.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=3/5)
deneme/12233434543.txt
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=2/5)
deneme/122343.txt
           0 100%    0.00kB/s    0:00:00 (xfer#3, to-check=1/5)
deneme/123.txt
           0 100%    0.00kB/s    0:00:00 (xfer#4, to-check=0/5)

sent 261 bytes  received 92 bytes  706.00 bytes/sec
total size is 0  speedup is 0.00
[root@fatihoz ~]# ls /tmp/deneme/
12233434543.txt  122343.txt  123.txt  1.txt

Uzakdaki bilgisayara dosya göndermek için:

[root@fatihoz ~]# rsync -avh --progress /home/fatih/1G.file  root@localhost:/tmp/
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is a8:6a:b1:43:9b:33:e4:78:cc:d0:ee:9d:e0:c2:0e:fe.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
root@localhost's password: 
sending incremental file list
1G.file
       1.02G 100%   23.49MB/s    0:00:41 (xfer#1, to-check=0/1)

sent 1.02G bytes  received 31 bytes  21.12M bytes/sec
total size is 1.02G  speedup is 1.00

find İle Dosya Adi Yakalama

Ocak 2, 2014 § Yorum yok § Kalıcı bağlantı

“{}” veya “-I” ya girilen parametre

[fatih@fatihoz deneme]$ find . -iname "*.txt" -print0 | xargs -0 -I {} cat {}

veya

[fatih@fatihoz deneme]$ find . -iname "*.txt" -print0 | xargs -0 -I match_file mv match_file ./yeni_klasor/

[fatih@fatihoz deneme]$ ls -laR
.:
total 12
drwxrwxr-x.  3 fatih fatih 4096 Jan  2 06:58 .
drwx------. 46 fatih fatih 4096 Jan  2 06:42 ..
drwxrwxr-x.  2 fatih fatih 4096 Jan  2 06:58 yeni_klasor

./yeni_klasor:
total 24
drwxrwxr-x. 2 fatih fatih 4096 Jan  2 06:58 .
drwxrwxr-x. 3 fatih fatih 4096 Jan  2 06:58 ..
-rw-rw-r--. 1 fatih fatih   13 Jan  2 06:42 112.txt
-rw-rw-r--. 1 fatih fatih   18 Jan  2 06:42 1345.txt
-rw-rw-r--. 1 fatih fatih   25 Jan  2 06:42 1.txt
-rw-rw-r--. 1 fatih fatih   29 Jan  2 06:42 456.txt

find ve xargs ile ” ” İçeren Dosyalarda Çalışmak

Ocak 2, 2014 § Yorum yok § Kalıcı bağlantı

Boşluk karakteri içeren dosya isimlerini yakalayabilmek için
find’da “-print0”, xargs’de “-0” parametreleri kullanılmalıdır.

[fatih@fatihoz deneme]$ ls -la
total 12
drwxrwxr-x.  2 fatih fatih 4096 Jan  2 06:25 .
drwx------. 46 fatih fatih 4096 Jan  2 06:13 ..
-rw-rw-r--.  1 fatih fatih    0 Jan  2 06:25 123123123.txt
-rw-rw-r--.  1 fatih fatih    0 Jan  2 06:25 123.txt
-rw-rw-r--.  1 fatih fatih    9 Jan  2 06:11 ali veli.txt
-rw-rw-r--.  1 fatih fatih    0 Jan  2 06:25 asdasd.txt

find "print" ile boşluk karakterli dosyaları yakalasa da çalışmaya olanak vermiyor
[fatih@fatihoz deneme]$ find . -name "*.txt" -print| cat
./ali veli.txt
./123.txt
./asdasd.txt
./123123123.txt
[fatih@fatihoz deneme]$ find . -name "*.txt" -print| xargs cat
cat: ./ali: No such file or directory
cat: veli.txt: No such file or directory

[fatih@fatihoz deneme]$ find . -name "*.txt" -print| xargs rm -rf
[fatih@fatihoz deneme]$ ls -la
total 12
drwxrwxr-x.  2 fatih fatih 4096 Jan  2 06:28 .
drwx------. 46 fatih fatih 4096 Jan  2 06:13 ..
-rw-rw-r--.  1 fatih fatih    9 Jan  2 06:11 ali veli.txt

Doğru kullanımı:
[fatih@fatihoz deneme]$ find . -name "*.txt" -print0 | xargs -0 rm -rf
[fatih@fatihoz deneme]$ ls
[fatih@fatihoz deneme]$ 



-print0’ın açıklamasi

-print0
True; print the full file name on the standard output, followed by a null character (instead of
the newline character that -print uses). This allows file names that contain newlines or other
types of white space to be correctly interpreted by programs that process the find output. This
option corresponds to the -0 option of xargs.

Xargs Kullanımı

Ocak 2, 2014 § Yorum yok § Kalıcı bağlantı

Xargs stdin’den input alıp bunu stdout’a echo ile basar.
ctrl-d ile stdout’a sonuc basılabilir.
xargs komutunun newline karakterlerini gözardı etmesine dikkat edelim.

[fatih@fatihoz ~]$ xargs 
deneme1
deneme2
yeni satır1
deneme1 deneme2 yeni satır1

“-t” parametresi ile xargs’in echo çağırdığı görülebilir:

[fatih@fatihoz ~]$ xargs -t
deneme satırı
/bin/echo deneme satırı 
deneme satırı

find ile xargs kullanımı

find ile bulduğumuz dosya isimlerini xargs’e input girip echo dışında iş yürütebiliriz.
Örn:


xargs’nin stdinden input alması ile ilgili bir diğer örnek:

[fatih@fatihoz ~]$ echo a b c d e | xargs
a b c d e

xargs’nin stdout’a bastığı çıktının bir satırda kaç adet olacağı “-n” parametresi ile verilebilir:

[fatih@fatihoz ~]$ echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | xargs -n 3
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17
[fatih@fatihoz ~]$ echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | xargs -n 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17

“-p” parametresi ile kullanicinin doğrulaması sağlanabilir:

[fatih@fatihoz ~]$ echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | xargs -p -n 4
/bin/echo 1 2 3 4 ?...y
/bin/echo 5 6 7 8 ?...1 2 3 4
y
/bin/echo 9 10 11 12 ?...5 6 7 8
y
/bin/echo 13 14 15 16 ?...9 10 11 12
y
/bin/echo 17 ?...13 14 15 16
y
17

find ile bulduğumuz dosya isimlerini xargs’ye sokabiliriz
Örn:

Dosya içeriklerine bakalım
[fatih@fatihoz deneme]$ grep . *
1.txt:Birinci dosyanin baslangici
1.txt:123123123123 123 12 3 12 31 23 1 2312 3 123 
1.txt:123
1.txt:12
1.txt:3
1.txt:12
1.txt:3
1.txt:12312312432454
1.txt:5
1.txt:3
1.txt:45
1.txt:34
1.txt:5
2.txt:İkinci dosyanin baslangici
2.txt:12312  5345 anan3 12312345
2.txt:34
2.txt:5

txt dosyalarda "dosyanin" metnini arayalim
[fatih@fatihoz deneme]$ find . -name "*.txt"| xargs grep "dosyanin"
./2.txt:İkinci dosyanin baslangici
./1.txt:Birinci dosyanin baslangici

txt dosyalarini silelim
[fatih@fatihoz deneme]$ find . -name "*.txt"| xargs rm -rf  

egrep İle Arama Renklendirme…

Aralık 30, 2013 § Yorum yok § Kalıcı bağlantı

egrep --color=always 'configuration|emulation' *.txt

veya

egrep --color=always -e 'configuration' -e 'emulation' *.txt

SQL’de Group by, having vs mantığı…

Aralık 30, 2013 § Yorum yok § Kalıcı bağlantı

SELECT ile dönen liste 3 parçaya ayrılabilir.
– Süzme işlemi (WHERE alt cümlesi ile yapılabilen)
– Sıralama işlemi (ORDER BY alt cümlesi ile yapılabilen)
– Geri dönen liste üzerinde yapılan işlemler (GROUP BY, HAVING, MAX, SUM, COUNT, MIN….vs.)

Bir SELECT cümlesi yazalım

SELECT Price
  FROM Customer
 WHERE Price < 100
   AND Price > 50

Bu cmleyi Price’a göre gruplandiralim:

  SELECT Count(*), Price
    FROM Customer
   WHERE Price < 100
     AND Price > 50
GROUP BY Price

Sonuçta Price bilgisi 100 ile 50 arasında olan Customer listesine düşük seviyeli liste diyelim. Bu düşük seviyeli listenin üzerine GRUOP BY ve COUNT işlemleri uygulandıktan sonra ortaya çıkan yeni listeye ise sonuç listesi adını verelim.

Bu bilgiler ışığında GROUP BY alt cümlesinin tanımı:
– Cümleden sonra parametre olarak belirtilen alanın veya alanların değerine göre düşük seviyeli listeyi parçalara ayırır, belirtilen alanın veya alanların kaç farklı değeri var ise o kadar düşük seviyeli liste oluşturur.

COUNT(*), MIN, MAX, AVERAGE gibi fonksiyonların nasıl çalıştıklarını anlamak için:
– Tüm bu fonksiyonlar, düşük seviyeli listenin tamamı üzerine çalışır. Eğer düşük seviyeli liste GRUOP BY ile bölünmüş ise, her bir parça için ayrı ayrı çalışırlar.

Yani son SQL cümlesinde yer alan Count(*) işlemi her Price değeri için bölünmüş olan düşük seviyeli listenin herbir parçası için çalışır. Ve ortaya sonuç listesi olarak, her parçanın içerisinde yer alan kayıt sayısı ve her parçanın ayıraçı konumundaki Price bilgisi çıkar. Örnek;

Count(*) - Price
    5            60
    7            70
... vb.




Örnek uygulama:;

  SELECT Count(*), Price, Name
    FROM Customer
   WHERE Price < 100
     AND Price > 50
GROUP BY Price

Yukarıki sorgu neden hata vermektedir:

Şimdi öncelikle düşük seviyeli listenin ne olduğunu bulalım;
– Price bilgisi 100 ile 50 arasında olan Customer bilgileri.. Id, Price, Name…vs.. vs.. Bu listeye ‘A’ listesi diyelim.

‘GRUOP BY’ işlemi olduğuna göre, elimizdeki düşük seviyeli ‘A’ listesi Price bilgisinin değerlerine göre bölümlere ayrılmıştır. Örnek olarak Price bilgisi 5 farklı değere sahip olsun elimizdeki ‘A’ listesi ‘A1, A2, A3, A4, A5′ şeklinde küçük listelere ayrılır.

Daha sonra COUNT(*) işlemi ile bu her bir küçük listenin adet bilgisi ile Price ve Name bilgisi sonuç listesine verilmiştir. Peki burada ki gariplik ne, neden hata veriyor. Sorun şu A listesinden A1′e geçiş sırasında her bir Price’a karşılık ‘n’ adet Name bilgisi oluşmuştur bu nedenle sonuç listesi oluşturulurken, Count bilgisi hesaplanmış, Price bilgisi tek olduğu için alınmış fakat hangi Name bilgisinin kullanılacağına karar verilememiştir.

Düşük Seviyeli Liste’nin son hali..

Id Price Name
1 60 Test60-1
2 60 Test60-2
3 70 Test70-1
4 70 Test70-2
5 80 Test80-1
6 90 Test90-1

‘Group By’ uygulandıktan sonraki düşük seviyeli listenin hali;

Price Alt Kümeler
60
Id Name
1 Test60-1
2 Test60-2
70
Id Name
1 Test70-1
2 Test70-2
80
Id Name
1 Test80-1
90
Id Name
1 Test90-1

İşte bu da son ipucu; SQL programlama dilinde herhangi bir liste oluşturabilmek için bir kademe altta yer alan listenin elemanları direkt olarak kullanılabilir ya da fonksiyonlar yardımı ile alt listelere ulaşılıp, toplam, en küçük, en büyük, ortalama.. vb. değerler elde edilebilir.

Bu yazı “http://esiyo.net/select-gruop-by-having/110” adresinden alınmış/özetlenmiştir.

Birden fazla text dosyasının içeriklerini görüntülemek

Aralık 27, 2013 § Yorum yok § Kalıcı bağlantı

grep kullanarak text dosyalarının boş olmayan satırlarını görüntüleyelim.

[deneme]$ grep . *
1.txt:asd
1.txt:asd
1.txt:as
1.txt:d
1.txt:234
1.txt:234
1.txt:23
1.txt:4
1.txt:34
1.txt:23
1.txt:4
2.txt:12312
2.txt:12
2.txt:3
2.txt:34
2.txt:45
2.txt:34
2.txt:5
2.txt:34
2.txt:5345
2.txt:3
2.txt:45
2.txt:34
2.txt:5

grep kullanarak boş satırları da görmek istiyorsak

deneme]$ grep ^ *
1.txt:asd
1.txt:asd
1.txt:as
1.txt:d
1.txt:
1.txt:
1.txt:234
1.txt:
1.txt:234
1.txt:23
1.txt:4
1.txt:34
1.txt:23
1.txt:4
2.txt:12312
2.txt:12
2.txt:3
2.txt:
2.txt:34
2.txt:45
2.txt:34
2.txt:5
2.txt:34
2.txt:5345
2.txt:3
2.txt:45
2.txt:34
2.txt:5


More kullanarak benzer etkiyi yapmak için

[deneme]$ more * | cat 
::::::::::::::
1.txt
::::::::::::::
asd
asd
as
d


234

234
23
4
34
23
4
::::::::::::::
2.txt
::::::::::::::
12312
12
3

34
45
34
5
34
5345
3
45
34
5

Aynı etkiyi head ile yapmak

[deneme]$ head -n 99999 * 
==> 1.txt <==
asd
asd
as
d


234

234
23
4
34
23
4

==> 2.txt <==
12312
12
3

34
45
34
5
34
5345
3
45
34
5