@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Betiğin Kod İçeriği :
Kod: Tümünü seç
#!/bin/bash
# Faal hizmet sayısı
running=$(systemctl list-units --type=service --state=running | tail -n +2 | wc -l)
# Devre dışı hizmet sayısı
inactive=$(systemctl list-units --type=service --state=inactive | tail -n +2 | wc -l)
# Durmuş hizmet sayısı
failed=$(systemctl list-units --type=service --state=failed | tail -n +2 | wc -l)
# Başlatılmayı bekleyen hizmet sayısı
waiting=$(systemctl list-units --type=service --state=waiting | tail -n +2 | wc -l)
# Sonuçları yazdır
echo "Faal hizmet sayısı: $running"
echo "Devre dışı hizmet sayısı: $inactive"
echo "Durmuş hizmet sayısı: $failed"
echo "Başlatılmayı bekleyen hizmet sayısı: $waiting"
dosyası olup aşağıda, betiğin her bir bölümünün ne yaptığını açıklayan bir inceleme bulunmaktadır...
1.Faal Hizmet Sayısı:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
running=$(systemctl list-units --type=service --state=running | tail -n +2 | wc -l)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
• systemctl list-units --type=service --state=running: Bu komut, çalışan (faal) hizmetleri listeler.
• tail -n +2: İlk satırı (başlık) atlar.
• wc -l: Satır sayısını sayarak faal hizmetlerin sayısını alır.
2.Devre Dışı Hizmet Sayısı:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
inactive=$(systemctl list-units --type=service --state=inactive | tail -n +2 | wc -l)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
• systemctl list-units --type=service --state=inactive: Devre dışı olan hizmetleri listeler.
• Diğer işlemler yukarıdakiyle aynıdır.
3.Durmuş Hizmet Sayısı:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
failed=$(systemctl list-units --type=service --state=failed | tail -n +2 | wc -l)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
• systemctl list-units --type=service --state=failed: Durmuş (başarısız) hizmetleri listeler.
• Diğer işlemler yukarıdakiyle aynıdır.
4.Başlatılmayı Bekleyen Hizmet Sayısı:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
waiting=$(systemctl list-units --type=service --state=waiting | tail -n +2 | wc -l)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
• systemctl list-units --type=service --state=waiting: Başlatılmayı bekleyen hizmetleri listeler.
• Diğer işlemler yukarıdakiyle aynıdır.
5.Sonuçları Yazdır:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo "Faal hizmet sayısı: $running"
echo "Devre dışı hizmet sayısı: $inactive"
echo "Durmuş hizmet sayısı: $failed"
echo "Başlatılmayı bekleyen hizmet sayısı: $waiting"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
• Bu komutlar, her bir hizmet durumunun sayısını ekrana yazdırır.
Betiği Çalıştırmak için Adımlar:
1. Betiği bir dosyaya kaydedin (örneğin, service_status.sh)
2. Dosyaya çalıştırma izni verin: chmod +x service_status.sh
3. Betiği çalıştırın: ./service_status.sh
Bu betik, sistem yöneticileri için hizmetlerin durumunu hızlı bir şekilde kontrol etmek ve yönetmek için yararlıdır.
SONUÇ :
