2
        set_include_path(get_include_path() . PATH_SEPARATOR . 'C:\wamp\www\Web Apps\backend\phpsec');
        include ('phpsec/Net/SSH2.php');
        $ssh = new Net_SSH2('www.example.com');
        if (!($ssh->login('userlogin', 'password'))) {
            exit('Login Failed');
        }

        echo "Login Success<br>";


        $output=$ssh->exec('crontab -e;30 17 * * 1 /path/to/command')

        echo "$output";

Here I am trying to set cron job. But it gives following error "Error opening terminal: unknown. /usr/bin/crontab.cagefs: "pico" exited with status 1 bash: 30: command not found" So how to set cron job using phpseclib?

neubert
  • 15,947
  • 24
  • 120
  • 212
  • That does sound like a problem on the server you are connecting to. Can you execute the line to edit the cronjob there without problems? – Nico Haase Dec 04 '17 at 13:09
  • I can delete the cron job there but I cannot add. @NicoHaase – Jesil Desouza Dec 04 '17 at 13:44
  • Check out https://stackoverflow.com/a/9625233/569976 . You might need a PTY to do some of that stuff idk – neubert Dec 04 '17 at 14:10
  • 1
    Try `crontab -l | { cat; echo -e "30 17 * * 1 /path/to/command"; } | crontab -` no need to open cron – Lawrence Cherone Dec 04 '17 at 14:12
  • 1
    @JesilDesouza the other comments should help you find a solution - this is not a problem based on PHP or phpseclib, but on a wrongly executed shell command – Nico Haase Dec 04 '17 at 14:18
  • @NicoHaase what should be the shell command – Jesil Desouza Dec 05 '17 at 04:49
  • The part you are putting into $ssh->exec() is the shell command to be executed, that's what this command is for ;) If this is completely new to you, I would strongly advise not to work on this script anymore, as you can screw up a lot with this.... – Nico Haase Dec 05 '17 at 08:15

1 Answers1

2

Write the following command in exec() function

  $ssh->exec('crontab -l | { cat; echo "* * * * * /path/to/command/"; } | crontab -');