FaizBlog LogoFaizBlog
Back to all articles
mikrotikhotspotschedulerscriptautomationtutorial

Cara Menghapus Pengguna Hotspot MikroTik Otomatis (Auto-Cleanup Voucher Expired)

Panduan otomatis menghapus voucher hotspot MikroTik yang sudah expired supaya database bersih dan performa router tetap ringan.

AI Insights

Generate a summary and suggested tags for this post.

Kalau usaha WiFi jalan sebulan aja, list user hotspot bisa membengkak ribuan — kebanyakan sudah expired tapi masih ada di database. Router jadi berat, backup lama. Solusinya: auto-delete expired user pakai Scheduler + Script.

Sebelum vs Sesudah Auto-Cleanup

Kenapa Perlu Auto Cleanup?

MasalahAkibat
DB user membengkakBackup config lambat
Scroll user manualSusah nyari user aktif
Search jadi lemotQuery CLI berat
Router load naikResponse Winbox lambat

Konsep Auto Cleanup

MikroTik tidak punya "auto-delete expired user" bawaan. Kita bikin sendiri dengan:

  1. Script → hapus user yang bytes-nya sudah habis / uptime sudah kelar
  2. Scheduler → jalankan script tersebut tiap jam / tiap hari

Konfigurasi Scheduler MikroTik

Script Hapus User Expired

Cara 1: Berdasarkan Bytes Habis

Kalau pakai limit-bytes-total (voucher paket kuota):

/system script
add name=hapus-expired source={
  :foreach u in=[/ip hotspot user find] do={
    :local limit [/ip hotspot user get $u limit-bytes-total];
    :local used  [/ip hotspot user get $u bytes-in];
    :if (($limit > 0) && ($used >= $limit)) do={
      /ip hotspot user remove $u
    }
  }
}

Cara 2: Berdasarkan Waktu (Uptime)

Kalau pakai session-timeout (voucher paket waktu):

/system script
add name=hapus-expired-time source={
  :foreach u in=[/ip hotspot user find where uptime>1d] do={
    /ip hotspot user remove $u
  }
}

Cara 3: Berdasarkan Comment Tanggal

Cara paling reliable — beri comment tanggal saat generate voucher, hapus yang > 7 hari:

:foreach u in=[/ip hotspot user find comment~"batch-2024-01"] do={
  /ip hotspot user remove $u
}

Setup Scheduler Otomatis

Panggil script tiap 1 jam:

/system scheduler
add name=hapus-expired \
  interval=1h \
  on-event="/system script run hapus-expired" \
  comment="Auto cleanup voucher expired"

Atau tiap hari jam 3 pagi (jam sepi):

/system scheduler
add name=hapus-expired-daily \
  start-time=03:00:00 \
  interval=1d \
  on-event="/system script run hapus-expired"

Kombinasi: Cleanup + Backup

Sebelum hapus, backup dulu:

/system script
add name=cleanup-with-backup source={
  /system backup save name=("bak-" . [/system clock get date]);
  /system script run hapus-expired
}

Tips Ekstra

TipsDetail
NotifikasiKirim log ke Telegram tiap cleanup
Batch per 100 userHindari lock DB kalau > 10.000 user
Log ke fileSimpan siapa saja yang dihapus
Jangan hapus activeCek dulu hotspot active sebelum remove

Common Mistake

KesalahanAkibatSolusi
Hapus user yg lagi loginSession terputusFilter yg aktif via active list
Interval terlalu sering (1m)Router boros CPUCukup tiap 1 jam
Script tanpa testBisa hapus salah userTest manual dulu, output ke log
Tanpa backupSusah recovery kalau salahBackup config sebelum cleanup

Kesimpulan

Auto-cleanup voucher expired = Script filter user + Scheduler interval. Setup sekali, database hotspot kamu tetap bersih selamanya. Untuk monitoring apa yang dihapus, kombinasikan dengan artikel Cara Monitoring Pengguna Hotspot MikroTik.