DEV Community

Fega Suseno
Fega Suseno

Posted on • Edited on

1

Make Cronjob Script With Log

Postingan ini hanyalah catatan untuk penulis. Ini adalah script cronjob yg dibuat untuk membuat log secara manual sekaligus menjaga ukuran file agar stabil sesuia rentang waktu yg di inginkan.

#!/bin/bash

# Cek apakah file ada
file=/var/log/renew-ssl.log

if [ ! -f "${file}" ]; then
   echo "===== End of Line =====" >> ${file}
fi


# Mauskan job yg akan di ekseskusi
ls -la


# Cek apakah job berjalan
if [ $? -eq 0 ]; then
   tgl=$(date +%c)
   # Agar insert log ke file ditambahkan di baris paling pertama
   sed -i "1i\\${tgl} -> Job Success" ${file}
else
   tgl=$(date +%c)
   sed -i "1i\\${tgl} -> Job Fail !!"  ${file}
fi

# Menjaga agar file hanya sampai baris 30
sed -i '31,$d' ${file}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay