cron etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
cron etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

15 Mayıs 2023 Pazartesi

cron İş Dosyaları

crontab Dosyasında PATH Ortam Değişkeni
Açıklaması şöyle. crontab dosyasında PATH ortam değişkenini kullanmamak daha iyi.
cron scripts have a limited path, that doesn't include iptables, so it's not found.
if you do something like echo $PATH >> /root/test.log you will see that cron has a path with just /usr/bin and /bin
crontab Dosyasında SHELL Ortam Değişkeni
Açıklaması şöylee
cron needs to know which shell to start, there can only be one. The SHELL variable in crontab doesn’t specify possible shells, it specifies the shell to use. cron reads the value in SHELL, if any, and uses that as the command to run; it doesn’t interpret : or any other symbol.

İşlerin Saklandığı Dosyalar
Şu dizinlerde saklanırlar.
/etc/cron.hourly 
/etc/cron.daily 
/etc/cron.weekly 
Örneğin cron.daily dizinine bakarsak çıktı olarak şunun gibi bir şey alırız.
-rwxr-xr-x   1 root root   539 Tue Apr 02 2019 22:13:44 apache2
-rwxr-xr-x   1 root root  1478 Tue May 28 2019 15:40:29 apt-compat
-rwxr-xr-x   1 root root   314 Wed Feb 13 2019 17:40:39 aptitude
-rwxr-xr-x   1 root root    77 Sat Feb 16 2019 11:10:23 apt-show-versions
-rwxr-xr-x   1 root root   355 Fri Dec 29 2017 09:02:08 bsdmainutils
-rwxr-xr-x   1 root root  1187 Fri Apr 19 2019 03:14:13 dpkg
-rwxr-xr-x   1 root root  4128 Sat Jul 20 2019 12:35:58 exim4-base
-rwxr-xr-x   1 root root   377 Tue Aug 28 2018 23:21:11 logrotate
-rwxr-xr-x   1 root root  1123 Sun Feb 10 2019 12:11:20 man-db
-rwxr-xr-x   1 root root  1403 Thu Mar 21 2019 22:42:36 ntp
-rwxr-xr-x   1 root root   249 Wed Sep 27 2017 17:45:23 passwd
-rw-r--r--   1 root root   102 Sun Jun 23 2019 18:49:01 .placeholder
-rwxr-xr-x   1 root root   383 Sat Mar 30 2019 17:10:38 samba
-rwxr-xr-x   1 root root   441 Sat Apr 06 2019 08:18:26 sysstat
% karakteri
Eğer komut içinde % karakteri varsa, \ karakteri ile escape etmek gerekir.

Örnek
Şöyle yaparız. Sabah 03:03 AM'de çalışır
3 3 * * * mongodump --out /var/backups/mongobackups/`date +"\%m-\%d-\%y"`
Birden fazla dosya çalıştırma
En kolay seçenek tüm dosyaları çalıştıracak ana bir shell dosyası oluşturmak
Örnek
Şöyle yaparız
for script in /home/user/scripts/enabled/*; do $script &>/dev/null; done
Full Path
Açıklaması şöyle
You should use in cron ALWAYS the full path to the executables. It is run in quite different environment and a lot of executables are not "reachable"

Bazı Örnekler
Dakika, saat ... şeklinde gider. Her X anlamında kullanmak istersek */X şeklinde kullanırız.

Örnek
Şöyle yaparız
0 8,12,16,20 * * * /opt/tools/var/log/zhrdct.log 2>&1
Örnek
Her gün saat 21:30'da çalışmasını istediğimiz iş için şöyle yaparız.
30 21 * * *  cp /home/user/folder_name -r  /home/user/public
Örnek
Her 15 dakikada bir çalışmasını istediğimiz iş için şöyle yaparız.
*/15 * * * * wget ...
Örnek - @reboot
Bilgisayar açılırken çalışan bir script için şöyle yaparız
@reboot sleep 15; /path/to/your/script >> /path/to/your/iofile.txt 2>&1
Örnek - @reboot
Şöyle yaparız
@reboot root /usr/bin/rtcwake -m no -l -t "$(/usr/bin/date -d 'today 16:00:00' '+%s')"

26 Mayıs 2020 Salı

cron servisi

Giriş
Açıklaması şöyle
cron runs tasks (system or user chosen) which need to be run at regular intervals.
Ayar Dosyaları
Şu dosyaları okur.
/etc/crontab,  /etc/cron.d/* ve /var/spool/cron/cronstabs/*
Her kullanıcının dosyası şöyledir.
cat -v /var/spool/cron/crontabs/{user}
Bu dosyaları düzenlemek için crontab komutu kullanılabilir.

Loglama
Açıklaması şöyle.
The running of jobs is already logged in the cron log in /var/cron/log (the path may differ between systems).
-p seçeneği
Açıklaması şöyle.
-p     Allows Cron to accept any user set crontables.
Açıklaması şöyle.
All crontab files have to be regular files or symlinks to regular files, they must not be executable or writable for anyone else but the owner. This requirement can be overridden by using the -p option on the crond command line.