Use PHP to create, edit and delete crontab jobs?

crontab command usage usage: crontab [-u user] file crontab [-u user] [ -e | -l | -r ] (default operation is replace, per 1003.2) -e (edit user’s crontab) -l (list user’s crontab) -r (delete user’s crontab) -i (prompt before deleting user’s crontab) So, $output = shell_exec(‘crontab -l’); file_put_contents(‘/tmp/crontab.txt’, $output.’* * * * * NEW_CRON’.PHP_EOL); echo … Read more

Crontab – Run in directory

All jobs are executed by a shell, so start that shell snippet by a command to change the directory. cd /path/to/directory && ./bin/myapp Concerning the use of && instead of ;: normally it doesn’t make a difference, but if the cd command fails (e.g. because the directory doesn’t exist) with && the application isn’t executed, … Read more

Where can I set environment variables that crontab will use?

You can define environment variables in the crontab itself when running crontab -e from the command line. LANG=nb_NO.UTF-8 LC_ALL=nb_NO.UTF-8 # m h dom mon dow command * * * * * sleep 5s && echo “yo” This feature is only available to certain implementations of cron. Ubuntu and Debian currently use vixie-cron which allows these … Read more

How to pass in password to pg_dump?

Create a .pgpass file in the home directory of the account that pg_dump will run as. The format is: hostname:port:database:username:password Then, set the file’s mode to 0600. Otherwise, it will be ignored. chmod 600 ~/.pgpass See the Postgresql documentation libpq-pgpass for more details.

tech