Temmuz 25, 2011 § § Kalıcı bağlantı
Bunu başarmak için:
Öncelikle bc_yapilacakis isimli dosyayi olusturalim.
Dosyanın içeriği
d = a / b
print a," divided by ",b," with scale ",scale," is ",d
quit
Şimdi bc_userparametre.sh isimli shell dosyasını oluşturalım.
Dosyanın içeriği
# This is a shell script to request two numbers
# and pass those numbers to the bc interpreter
# for doing a calculation
echo -n "Enter numerator (top number) "
read var1
echo -n "Enter denominator (bottom number) "
read var2
echo -n "Enter scope (number of decimal places) "
read var3
cat <<eee > bc_parametreler
a = $var1
b = $var2
scale = $var3
eee
bc -q bc_parametreler bc_yapilacakis
rm -f bc_parametreler
echo ""
Görüldüğü gibi bc_userparametre.sh dosyasi bc_parametreler isimli dosyayi oluşturuyor.
bc ise quite modda önce bc_parametreler sonra bc_yapilacakis dosyasını okuyarak işini tamamlıyor.
Temmuz 21, 2011 § § Kalıcı bağlantı
iostat kullanımı:
$ iostat
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 194.72 1096.66 1598.70 2719068704 3963827344
sda1 178.20 773.45 1329.09 1917686794 3295354888
sda2 16.51 323.19 269.61 801326686 668472456
sdb 371.31 945.97 1073.33 2345452365 2661206408
sdb1 371.31 945.95 1073.33 2345396901 2661206408
sdc 408.03 207.05 972.42 513364213 2411023092
sdc1 408.03 207.03 972.42 513308749 2411023092
Sadece CPU kullanımını görmek
$ iostat -c
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Sadece disk I/O’unu görmek
$ iostat -d
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 194.71 1096.61 1598.63 2719068720 3963827704
sda1 178.20 773.41 1329.03 1917686810 3295355248
sda2 16.51 323.18 269.60 801326686 668472456
sdb 371.29 945.93 1073.28 2345452365 2661209192
sdb1 371.29 945.91 1073.28 2345396901 2661209192
sdc 408.01 207.04 972.38 513364213 2411024484
sdc1 408.01 207.02 972.38 513308749 2411024484
Network devicelarını ve NFS partitionlarının bilgilerini görmek:
$ iostat -n
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %sys %iowait %idle
4.33 0.01 1.16 0.31 94.19
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 2.83 0.35 5.39 29817402 457360056
sda1 3.32 50.18 4.57 4259963994 387641400
sda2 0.20 0.76 0.82 64685128 69718576
sdb 6.59 15.53 42.98 1318931178 3649084113
sdb1 11.80 15.53 42.98 1318713382 3649012985
Device: rBlk_nor/s wBlk_nor/s rBlk_dir/s wBlk_dir/s rBlk_svr/s wBlk_svr/s
192.168.1.4:/home/data 90.67 0.00 0.00 0.00 5.33 0.00
192.168.1.4:/backup 8.74 0.00 0.00 0.00 8.74 0.00
192.168.1.8:/media 0.02 0.00 0.00 0.00 0.01 0.00
MB cinsinden istatistikleri görmek
$ iostat -m
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 194.70 0.54 0.78 1327670 1935463
sda1 178.19 0.38 0.65 936370 1609060
sda2 16.51 0.16 0.13 391272 326402
sdb 371.27 0.46 0.52 1145240 1299425
sdb1 371.27 0.46 0.52 1145213 1299425
sdc 407.99 0.10 0.47 250666 1177259
sdc1 407.99 0.10 0.47 250639 1177259
Belirli bir device ın istatistiklerini görmek
$ iostat -p sda
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 194.69 1096.51 1598.48 2719069928 3963829584
sda2 336.38 27.17 54.00 67365064 133905080
sda1 821.89 0.69 243.53 1720833 603892838
Genişletilmiş istatistikler için
$ iostat -x
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 27.86 63.53 61.77 132.91 1096.46 1598.40 13.84 0.21 1.06 2.28 44.45
sda1 0.69 33.22 48.54 129.63 773.30 1328.84 11.80 1.39 7.82 2.28 40.57
sda2 27.16 30.32 13.23 3.28 323.13 269.56 35.90 0.55 32.96 3.44 5.68
sdb 39.15 215.16 202.20 169.04 945.80 1073.13 5.44 1.05 2.78 1.64 60.91
sdb1 39.15 215.16 202.20 169.04 945.77 1073.13 5.44 1.05 2.78 1.64 60.91
sdc 8.90 3.63 356.56 51.40 207.01 972.24 2.89 1.04 2.56 1.55 63.30
sdc1 8.90 3.63 356.55 51.40 206.99 972.24 2.89 1.04 2.56 1.55 63.30
Belirli bir partition için istatistikler
$ iostat -x sda1
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda1 0.69 33.21 48.54 129.62 773.23 1328.76 11.80 1.39 7.82 2.28 40.56
Belirli aralıklarla (2 saniyede bir) iostat çıktısnı güncellemek
$ iostat 2
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 194.67 1096.39 1598.33 2719070584 3963891256
sda1 178.16 773.26 1328.79 1917688482 3295418672
sda2 16.51 323.11 269.54 801326878 668472584
sdb 371.22 945.74 1073.08 2345454041 2661251200
sdb1 371.22 945.72 1073.08 2345398577 2661251200
sdc 407.93 207.00 972.19 513366813 2411036564
sdc1 407.93 206.98 972.19 513311349 2411036564
..
2 saniyede birr 3 kere çalıştırmak
iostat 2 3
mpstat kullanmak
mpstat ile CPU kullanım istatistikleri toplanabilir
$ mpstat
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
10:25:32 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
10:25:32 PM all 5.68 0.00 0.49 2.03 0.01 0.02 0.00 91.77
Her core için bilgi toplamak
$ mpstat -P ALL
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011 _x86_64_ (4 CPU)
10:28:04 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
10:28:04 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.99
10:28:04 PM 0 0.01 0.00 0.01 0.01 0.00 0.00 0.00 0.00 99.98
10:28:04 PM 1 0.00 0.00 0.01 0.00 0.00 0.00 0.00 0.00 99.98
10:28:04 PM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
10:28:04 PM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
Temmuz 21, 2011 § § Kalıcı bağlantı
cat exitstatus.sh
#! /bin/bash
echo -e "Successful execution"
echo -e "====================="
echo "hello world"
# Exit status returns 0, because the above command is a success.
echo "Exit status" $?
echo -e "Incorrect usage"
echo -e "====================="
ls --option
# Incorrect usage, so exit status will be 2.
echo "Exit status" $?
echo -e "Command Not found"
echo -e "====================="
bashscript
# Exit status returns 127, because bashscript command not found
echo "Exit status" $?
echo -e "Command is not an executable"
echo -e "============================="
ls -l execution.sh
./execution.sh
# Exit status returns 126, because its not an executable.
echo "Exit status" $?
Temmuz 21, 2011 § § Kalıcı bağlantı
Nic’in özelliklerinin elde edilmesi
ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: d
Wake-on: d
Link detected: yes
Duplex değeri için 3 olasılık vardır
- Full duplex : Enables sending and receiving of packets at the same time. This mode is used when the ethernet device is connected to a switch.
- Half duplex : Enables either sending or receiving of packets at a single point of time. This mode is used when the ethernet device is connected to a hub.
- Auto-negotiation : If enabled, the ethernet device itself decides whether to use either full duplex or half duplex based on the network the ethernet device attached to.
ethtool -s ile nic özellikleri değiştirilebilir.
autoneg özelliğini değiştirelim.
ifdown eth0
eth0 device: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
eth0 configuration: eth-bus-pci-0000:0b:00.0
ethtool -s eth0 autoneg off
ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: Not reported
Advertised auto-negotiation: No
Speed: Unknown! (65535)
Duplex: Unknown! (255)
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: off
Supports Wake-on: g
Wake-on: g
Link detected: no
# ifup eth0
Nic’in speed değerini sabitlemek için:
ethtool -s eth0 speed 100 autoneg off
ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: Not reported
Advertised auto-negotiation: No
Speed: Unknown! (65535)
Duplex: Unknown! (255)
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: off
Supports Wake-on: g
Wake-on: g
Link detected: no
ethtool -i ile firmware ve driver özellikleri öğrenilebilir.
# ethtool -i eth0
driver: bnx2
version: 2.0.1-suse
firmware-version: 1.9.3
bus-info: 0000:04:00.0
Nic’in ağ istatistiklerini öğrenmek için ethtool -S kullanılabilir
# ethtool -S eth0
NIC statistics:
rx_bytes: 74356477841
rx_error_bytes: 0
tx_bytes: 110725861146
tx_error_bytes: 0
rx_ucast_packets: 104169941
rx_mcast_packets: 138831
rx_bcast_packets: 59543904
tx_ucast_packets: 118118510
tx_mcast_packets: 10137453
tx_bcast_packets: 2221841
tx_mac_errors: 0
tx_carrier_errors: 0
rx_crc_errors: 0
rx_align_errors: 0
tx_single_collisions: 0
tx_multi_collisions: 0
tx_deferred: 0
tx_excess_collisions: 0
tx_late_collisions: 0
tx_total_collisions: 0
rx_fragments: 0
rx_jabbers: 0
rx_undersize_packets: 0
rx_oversize_packets: 0
rx_64_byte_packets: 61154057
rx_65_to_127_byte_packets: 55038726
rx_128_to_255_byte_packets: 426962
rx_256_to_511_byte_packets: 3573763
rx_512_to_1023_byte_packets: 893173
rx_1024_to_1522_byte_packets: 42765995
rx_1523_to_9022_byte_packets: 0
tx_64_byte_packets: 3633165
tx_65_to_127_byte_packets: 51169838
tx_128_to_255_byte_packets: 3812067
tx_256_to_511_byte_packets: 113766
tx_512_to_1023_byte_packets: 104081
tx_1024_to_1522_byte_packets: 71644887
tx_1523_to_9022_byte_packets: 0
rx_xon_frames: 0
rx_xoff_frames: 0
tx_xon_frames: 0
tx_xoff_frames: 0
rx_mac_ctrl_frames: 0
rx_filtered_packets: 14596600
rx_discards: 0
rx_fw_discards: 0
Network düzgün çalışmıyorsa
- Speed ve Duplex değerlerinin “Unknown” olmasına
- Link detection değerinin No olmasına
bakılabilir.
Nic’in ledini yakmak için -p kullanılabilir
ethtool -p eth0
Temmuz 21, 2011 § § Kalıcı bağlantı
$ split --bytes=5M file.txt
$ ls -lh
-rw------- 1 ramesh programmers 15.2M Apr 2 13:13 file.txt
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xaa
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xab
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xac
-rw------- 1 ramesh programmers 128K Apr 2 18:54 xad
Dosya isimlerinin daha anlamlı olması için prefix kullanılabilir
$ split --bytes=5M file.txt split_
$ ls -lh
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_aa
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_ab
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_ac
-rw------- 1 ramesh programmers 128K Apr 2 18:54 split_ad
-rw------- 1 ramesh programmers 15.2M Apr 2 13:13 file.txt
Dosyaları birleştirmek için
$ cat xa? > outfile.txt.zip
(or)
$ cat split_a? > outfile.txt.zip
Temmuz 21, 2011 § § Kalıcı bağlantı
zip hem Linux hem de windows kullanıcılarının açabileceği bir dosya formatı olarak
sıkıştırma için tercih edilebilir.
Bir adet dosyayı sıkıştırmak
zip output-file.zip input-file
Birden fazla dosyayı sıkıştırmak
zip output-file.zip input-file1 input-file2 input-file3 ...
Klasör sıkıştırmak
zip -r output-file.zip input-dir-name
Sıkıştırırken şifrelemek için -e kullanılabilir
zip -e output-file.zip intput-file
Sıkıştırılmış dosyaları açmak için
zip -e output-file.zip intput-file
Temmuz 21, 2011 § § Kalıcı bağlantı
lshal
lshw
bu sonuclarda “vendor” aranabilir.
lspci kullanılarak
lspci -vvnn
Temmuz 21, 2011 § § Kalıcı bağlantı
Boş satırları görmezden gelerek dosya karşılaştırmak
diff -w file1.txt file2.txt
2c2
< hscripts.com
---
> HSCRIPTS.com
4d3
< Hioxindia.com
diff -y kullanarak satır satır karşılaştırma yapılabilir.
-b ile boş satırlar ihmal ediliyor
diff -by file1.txt file2.txt
HIOX TEST HIOX TEST
hscripts.com | HSCRIPTS.com
with friend ship with friend ship
Hioxindia.com <
diff -i ile case insensitive karşılaştırma yapılabilir.
diff -iy file1.txt file2.txt
HIOX TEST HIOX TEST
hscripts.com HSCRIPTS.com
with friend ship | with friend ship
Hioxindia.com <
Diff sonucunu okumak:
cat email
1 John erpl08@ed
2 Joe CZT@cern.ch
3 Kim ks@x.co
4 Keith keith@festival
cat addresses
1 John erpl08@ed
2 Joe CZT@cern.ch
3 Jean JRS@pollux.ucs.co
4 Jim jim@frolix8
5 Kim ks@x.co
6 Keith keith@festival
diff email addresses
2a3,4
> Jean JRS@pollux.ucs.co
> Jim jim@frolix8
To make these files match you need to add (a) lines 3 and 4 (3,4) of the file addresses (>) after line 2 in the file email.
diff cookies.old cookies.new
5c5
< One cup vanilla extract
---
> One teaspoon vanilla extract
7d6
< Six ounces chopped liver
21a22
> Note: The previous version of this recipe had a few errors!
The output is actually a description of how to transform the old file into the new one. Here, diff is telling you three things:
· The fifth line of the file has undergone a change. The 5c5 message says to replace line 5 of the old file with line 5 of the new file. Both the old and new text are displayed, separated by a line of three dashes. (The less-than (<) notation means “remove this line,” and the greater-than (>) sign means “add this line.”)
· Line 7 of the old file does not appear in the new file. The 7d6 message says to delete line 7 from the old file, and the files will then be in sync, starting at line 6 of the new file. The text to be deleted is displayed on the next line.
· A line was added to the new file. The 21a22 message says to add a new line after line 21 of the old file. The text to be added is displayed on the final line of the output.
Temmuz 21, 2011 § § Kalıcı bağlantı
Veri dosyasinin içeriği:
”
406378:Sales:Itorre:Jan
031762:Marketing:Nasium:Jim
636496:Research:Ancholie:Mel
396082:Sales:Jucacion:Ed
”
olsun.
İlk 6 sütunun alınmasu
cut -c1-6 company.data
406378
031762
636496
396082
4. ve 8. sütunun alınması
cut -c4,8 company.data
3S
7M
4R
0S
seperator olarak “:” kullanıp 3. kolonu almak
cut -d: -f3 company.data
Itorre
Nasium
Ancholie
Jucacion
-c [n | n,m | n-m] Specify a single column, multiple columns (separated by a comma), or range of columns (separated by a dash). -f [n | n,m | n-m] Specify a single field, multiple fields (separated by a comma), or range of fields (separated by a dash). -dc Specify the field delimiter. -s Suppress (don’t print) lines not containing the delimiter.
Temmuz 21, 2011 § § Kalıcı bağlantı
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/csh
/bin/sh
/usr/bin/es
/usr/bin/ksh
/bin/ksh
/usr/bin/rc
/usr/bin/tcsh
/bin/tcsh
/usr/bin/esh
/bin/dash
/bin/bash
/bin/rbash
/usr/bin/screen
/bin/ksh93
Shell değiştirmek
$ echo $0
/bin/bash
$ exec /bin/sh
$ echo $0
/bin/sh
Kalıcı olarak shell değiştirmek
$ chsh -s /bin/sh
Password: