Skip to content

Instantly share code, notes, and snippets.

@rijdz
Last active January 5, 2020 00:42
Show Gist options
  • Save rijdz/580f8272ce644ac92e76aca1ef9ecf7b to your computer and use it in GitHub Desktop.
Save rijdz/580f8272ce644ac92e76aca1ef9ecf7b to your computer and use it in GitHub Desktop.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment