rijdz
5/20/2019 - 6:40 AM

Unix - Cron Job

Cronjob on Centos

Testing Cron

Goals

there will be output text "foobar" on test.txt for each minute and for second line there will be environment of existing OS on /tmp/env.output

How to?

  • Run command
crontab -e
  • write this
* * * * * /bin/echo "foobar" >> /var/repo/test-script/test.txt
* * * * * env > /tmp/env.output
0 8 * * 1-5 /var/repo/script/myfile.sh
  • make it executable for bash script
chmod +x /var/repo/script/myfile.sh
  • check destination file

Output File

  • 1 foobar foobar

  • 2 XDG_SESSION_ID=33110 SHELL=/bin/sh USER=pp PATH=/usr/bin:/bin PWD=/home/pp LANG=en_US.UTF-8 SHLVL=1 HOME=/home/pp LOGNAME=pp XDG_RUNTIME_DIR=/run/user/1000 _=/usr/bin/env

grep "PC_TRANSACTION_run.sh" /var/log/cron