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)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay