Postingan

Menampilkan postingan dengan label Bash

how to run script at boot using systemd

Example I have script to run at boot Create your own script, my example is start-myscript.sh Make that the script executable with: chmod u+x /usr/local/bin/start-myscript.sh And then create a file named end with .service, this file will be used to call the start-myscript.sh, example: myscript.service file should look like this: [Unit] Description=My Script [Service] ExecStart=/usr/local/bin/start-myscript.sh [Install] WantedBy=multi-user.target Now do a few more steps to enable and use the .service file: Place it in /lib/systemd/system folder with say a name of myscript.service Start it: sudo systemctl start myscript Enable it to run at boot: sudo systemctl enable myscript Stop it: sudo systemctl stop myscript

Increase Bash History Size

Increase HISTSIZE – the number of commands to remember in the command history (the default value is 500). #export HISTSIZE=10000 Increase HISTFILESIZE – the maximum number of lines contained in the history file (the default value is 500). #export HISTFILESIZE=10000 #source ~/.bashrc https://www.shellhacks.com/tune-command-line-history-bash/

Bash scripting backup task scheduler

Berikut adalah cara membuat task scheduler di linux tanpa menggunakan crontab, banyak cara yang bisa dilakukan namun kali ini akan menggunakan bash script. Script nya sederhana seperti dibawah ini ada 2 file backup-db.sh dan backup-db-scheduler.sh Untuk tutorial ini membahas  backup-db-scheduler.sh #!/bin/bash while true do sleep 2m bash /opt/backup-db.sh done Simpan script diatas misalnya dengan nama backupdbscheduler.sh Kemudian chmod +x backup-db-scheduler.sh Script diatas akan menjalankan script backup-db.sh setiap 2 menit. Jalan script di background dengan perintah #./backup-db-scheduler.sh & Untuk lihat process yang di background ps aux | grep process_name Untuk menghentikan process yang diinginkan kill -9 process_id Simpan di rc.local agar ketika server reboot bisa berjalan kembali scriptnya. Tambahkan di /etc/rc.local script dibawah ini diatas script exit 0 /opt/backup-db-scheduler.sh