Create Linux crontab in PHP while using CPanel jailshell

1.1k Views Asked by At

I'm attempting to manage crontabs in PHP without reinventing anything. Reading them works as expected. Writing crons in PHP does not. I have got the first code sample below to work with full shell access turned on. I'm wondering if there is a way get PHP to save a crontab with jailshell? I got it to work through jailshelled ssh via crontab -e and the default nano editor. Please and thank you.

passthru('echo "'.$cron.'" | crontab -', $response);

'-' does not exist. usage: crontab file crontab [ -e | -l | -r ] -e (edit user's crontab) -l (list user's crontab) -r (delete user's crontab)

passthru('echo "'.$cron.'" | env EDITOR=echo crontab -e', $response);

/var/tmp/14760.BIN_JAIL_SAFE_CRONTAB_PL__.RCL3wRzOq0IQGdOU.tmp crontab: no changes

passthru('echo "'.$cron.'" | env EDITOR=cat crontab -e', $response);

SHELL="/usr/local/cpanel/bin/jailshell" */5 * * * * /path/to/job -with args */5 * * * * /path/to/job -with args crontab: no changes

1

There are 1 best solutions below

0
On

I think best solution if use php and bash

  • crontab -u user -l > temp_file
  • edit file (add, delete, modify lines with PHP code
  • crontab -u user crontab.txt