Linux’de mesaj iletmek

Ağustos 25, 2011 § Yorum yok § Kalıcı bağlantı

1-xterm penceresi içinde top koşmak
ve xterm penceresi içinde echo ile mesaj göndermek

xterm -e "top -c; sleep 10"
xterm -e "watch echo 'Bu bir mesajdır'"

SSH ile birlikte kullanmak için

ssh -Y fatih@localhost  'export DISPLAY=:0 && xterm -e watch echo "Bu bir mesajdır"'

2-notify-send yazılı ile

notify-send "welcome to Linux message box"

SSh ile birlikte kullanımı

ssh -Y fatih@localhost  'export DISPLAY=:0 && notify-send "welcome to Linux message box"'

3-zenity kullanmak

zenity --info --title='Message' --text='Linux redhat '

SSH ile kullanmak

ssh -Y fatih@localhost  'export DISPLAY=:0 && zenity --info --title='Message'  -text='Linux redhat '"

4-kdialog kullanmak

kdialog --title "New Mail Has Arrived" --passivepopup "it will terminate withing 5 minutes" 5

SSH ile kullanmak

ssh -Y fatih@localhost  'export DISPLAY=:0 && kdialog --title "New Mail Has Arrived" --passivepopup "it will terminate withing 5 minutes" 5'

5-En güzel yol:

$ who
jdoe     pts/0        2014-03-09 16:19 (10.3.2.98)
mary     pts/1        2014-03-09 14:10 (10.3.2.123
$ echo "Bu sesaj jdoeya" > /dev/pts/0
$ echo "Bu da sevgili Marrye" > /dev/pts/1

SSh ile yapılması

$ ssh root@hedef 'who'
$ ssh root@hedef 'echo "Bu da sevgili Marrye" > /dev/pts/1'

David Lynch

Ağustos 25, 2011 § Yorum yok § Kalıcı bağlantı

David Lynch’in Lost Highway’ini izledim.
1 cümle ile ifade edecek olsam filmi:
“David Lynch is a brain fuck!” derdim….

Konsoldan ses kontrolü/ayarı yapmak

Ağustos 22, 2011 § Yorum yok § Kalıcı bağlantı

Konsoldan ses ayarı yapabilmek icin “alsamixer” kullanılabilir.
Bunun için

sudo apt-get install alsa alsa-tools
sudo adduser yourusername audio
alsamixer

Açık bağlantıların tesbiti

Ağustos 19, 2011 § Yorum yok § Kalıcı bağlantı

netstat -lantp | grep ESTABLISHED |awk '{print $5}' | awk -F: '{print $1}' | sort -u

Bilgisayara bağlanmış kullanıcının bütün processlerini öldürmek(login shell dahil)


pkill -KILL -u username

Aria2 ile dosya download etmek

Ağustos 18, 2011 § Yorum yok § Kalıcı bağlantı

Aria2 ile çoklu bağlantili, max bandwith ile dosya downloadu mümkün.
Geliştiricileri süper iş çıkarmış.
Kullanımı:

aria2c "http://host/file.zip"

2 kaynaktan aynı dosyanın indirilmesi

aria2c "http://host/file.zip" "http://mirror/file.zip"

HTTP ve FTP nin beraber kullanımı

aria2c "http://host1/file.zip" "ftp://host2/file.zip"

Bir dosyadaki fileların download edilmesi

aria2c -ifiles.txt -j2

Sayı sequanci ile download

aria2c -Z -P "http://host/image[000-100].png"

Ayrıntılı bilgi

Never say no to Panda!

Ağustos 17, 2011 § Yorum yok § Kalıcı bağlantı

Dosya isimlerini değiştirmek

Ağustos 17, 2011 § Yorum yok § Kalıcı bağlantı

    echo "bizim ilk filemiz:"${filename:4:19}
    #echo ${filename[0]:4}".birles."$i".mp4"
 
    avimerge -i 32*mp4 -o ${filename:4:19}.birles.$i.mp4
    echo "avimerge bitti basa don"

if kullanımı

Ağustos 17, 2011 § Yorum yok § Kalıcı bağlantı

Dosya için varlık kontrolü

if [ -a tmp.tmp ]; then
   rm -f tmp.tmp # Make sure we're not bothered by an old temporary file
fi

Dizin için varlık kontrolü

if [ -d ~/.kde ]; then
    echo "You seem to be a kde user."
fi

Dosyanın regular dosya olarak varlığının kontrolü icin -f regularfile
Regular dosyalar blok veya karakter special dosyaları(/dev dizinindeki device tanımlayan kernel dosyaları) değildir.

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

Dosyayı inceleyen kullanıcı dosyanın sahibi mi?

if [ -O file ]; then
    chmod 600 file # Makes the file private, which is a bad idea if you don't own it
fi

Dosya okunabiliyor mu?(izinleri var mı)

if [-r file ]; then
    content=$(cat file) # Set $content to the content of the file
fi

Dosya 0 bytedan farklı okunabilen bir dosya mı?

if [ -s logfile ]; then
  gzip logfile    # Backup the old logfile
  touch logfile # before creating a fresh one.
fi

Dosya yazılabilir mi?

if [ -w /dev/hda ]; then
    grub-install /dev/hda
fi

Dosya çalıştırılabilir mi?(Dizinler için içeriği listelenebilir mi?)

if [ -x /root ]; then
    echo "You can view the contents of the /root directory."
fi

Dosyaların değiştirilme tarihini karşılaştırmak:
(olderfile yokken de True döner)

if [ newerfile -nt olderfile ]; then
    echo "story.txt1 is newer than story.txt; I suggest continuing with the former."
fi

veya

if [ /mnt/remote/remotefile -ot localfile ]; then
    cp -f localfile /mnt/remote/remotefile # Make sure the remote location has the newest version of the file, too
fi

Dosyaların inodelarını karşılaştırmak.

if [ /dev/cdrom -ef /dev/dvd ]; then
    echo "Your primary cd drive appears to read dvd's, too."
fi

String karşılaştırmak:

if [ "$1" == "moo" ]; then
    echo $cow # Ever tried executing 'apt-get moo'?
fi
if [ "$userinput" != "$password" ]; then
    echo "Access denied! Wrong password!"
    exit 1 # Stops script execution right here
fi

Stringin uzunluğu 0’dan büyük mü?

if [ -n "$userinput" ]; then
    userinput=parse($userinput) # Only parse if the user actually gave some input.
fi

String boş string mi?

if [ -z $uninitializedvar ]; then
    uninitializedvar="initialized" # -z returns true on an uninitialized variable, so we initialize it here.
fi

String regex’e uygun mu?

if [[ "$email" =~ "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b" ]]; then
    echo "\$email contains a valid e-mail address."
fi

Sayıları karşılaştırmak:

if [ $? -eq 0 ]; then # $? returns the exit status of the previous command
    echo "Previous command ran succesfully."
fi
if [ $(ps -p $pid -o ni=) -ne $(nice) ]; then
    echo "Process $pid is running with a non-default nice value"
fi
 
if [ $num -lt 0 ]; then
    echo "Negative numbers not allowed; exiting..."
    exit 1
fi
[ NUM1 -ne NUM2 ]
NUM1 is Not Equal to NUM2.
[ NUM1 -gt NUM2 ]
NUM1 is Greater Than NUM2.
[ NUM1 -ge NUM2 ]
NUM1 is Greater than or Equal to NUM2.
[ NUM1 -lt NUM2 ]
NUM1 is Less Than NUM2.
[ NUM1 -le NUM2 ]
NUM1 is Less than or Equal to NUM2.

Diğer kullanım örnekleri

if (( $? == 0 )); then # $? returns the exit status of the previous command
    echo "Previous command ran succesfully."
fi
 
if (( $(ps -p $pid -o ni=) != $(nice) )); then
    echo "Process $pid is running with a non-default nice value"
fi
 
if (( $num < 0 )); then
    echo "Negative numbers not allowed; exiting..."
    exit 1
fi
(( NUM1 != NUM2 )) NUM1 is not equal to NUM2.
(( NUM1 > NUM2 )) NUM1 is greater than NUM2.
(( NUM1 >= NUM2 )) NUM1 is greater than or equal to NUM2.
(( NUM1 < NUM2 )) NUM1 is less than NUM2.
(( NUM1 <= NUM2 )) NUM1 is less than or equal to NUM2.

history kullanımı

Ağustos 17, 2011 § Yorum yok § Kalıcı bağlantı

Komutların sırasını ve tarihlerini görebilmek için


export HISTTIMEFORMAT='%F %T '
 history | more
1  2008-08-05 19:02:39 service network restart
2  2008-08-05 19:02:39 exit
3  2008-08-05 19:02:39 id
4  2008-08-05 19:02:39 cat /etc/redhat-release

Ctrl+R ile historyde arama yapılabilir.
Her Ctrl+R basıldığında bir diğer arama sonucu getirilir.
Sağ-Sol ok tuşları ile bulunan komut alınabilir.

History sırasına göre komut çalıştırmak için

 history | more
1  service network restart
2  exit
3  id
4  cat /etc/redhat-release
 
 !4
cat /etc/redhat-release
Fedora release 9 (Sulphur)

Başlangıcı bilinen (ps ile başlayan son komut) komutu history’de çalıştırmak

!ps
ps aux | grep yp
root     16947  0.0  0.1  36516  1264 ?        Sl   13:10   0:00 ypbind
root     17503  0.0  0.0   4124   740 pts/0    S+   19:19   0:00 grep yp

Komutun historyde görünmemesi için

export HISTCONTROL=ignorespace
ls -ltr
pwd
 service httpd stop 
[Note that there is a space at the beginning of service,
to ignore this command from history]
history | tail -3
67  ls -ltr
68  pwd
69  history | tail -3

gdb c debugger kullanımı

Ağustos 17, 2011 § 1 yorum § Kalıcı bağlantı

Programı yazalım

$ vim factorial.c
# include <stdio.h>

int main()
{
	int i, num, j;
	printf ("Enter the number: ");
	scanf ("%d", &num );

	for (i=1; i<num; i++)
		j=j*i;

	printf("The factorial of %d is %d\n",num,j);
}
$ cc factorial.c

$ ./a.out
Enter the number: 3
The factorial of 3 is 12548672

gdb kullanabilmek için ”cc -g” ile compile edelim

$ cc -g factorial.c

Önce gdb yi a.out için çalıştırıyoruz.

$ gdb a.out

Sonra break point koyuyoruz

Syntax:

break line_number

    *
      break [file_name]:line_number
    *
      break [file_name]:func_name

break 10
Breakpoint 1 at 0x804846f: file factorial.c, line 10.

“run ” ile programı çalıştır

run [args]

run
Starting program: /home/sathiyamoorthy/Debugging/c/a.out

İlk break pointe kadar program çalışır eder

Breakpoint 1, main () at factorial.c:10
10			j=j*i;

Bu noktada debug edebiliriz
Değişken değerlerine bakalım

Syntax: print {variable}

Examples:
print i
print j
print num

(gdb) p i
$1 = 1
(gdb) p j
$2 = 3042592
(gdb) p num
$3 = 3
(gdb)

gdb ile kullanılabilecek diğer seçenekler
c (continue kısaltması): Bir sonraki break point e kadar sür.
n (next kısaltması): Birsonraki satırı sür
s (step kısaltması): n ile aynıdır fakat fonksiyon geldiğinde fonksiyonu tek satır olarak almaz fonksiyona gidip onu satır satır çalıştırır

Diğer seçeekler
l – list
p – print
c – continue
s – step
ENTER: bir önceki emri tekrar et
l command: Kaynak kodu görmek için kullanılır
bt: backtrack – Print backtrace of all stack frames, or innermost COUNT frames.
help – help TOPICNAME.
quit – çıkış

kaynak

Neredeyim ben!?

Ağustos, 2011 arşivinde geziniyorsun.