Jump to content

Recommended Posts

Well, I was trying to start a cron job in cpanel.But the php code is throwing error.The Code is:-

 

<?php
#!/usr/bin/expect
$line1=shell_exec('spawn ssh username@hostname');
$line2=shell_exec('expect "password:"');
$line3=shell_exec('send "mypassword"');
$line4=shell_exec('interact');
$line7=shell_exec('EOD');
#!/bin/sh
$line5=shell_exec('find srcdirectory -maxdepth 1 -mtime -1 -exec scp -r "{}" username@hostname:targetdirectory \;');
echo "<pre>$line1</pre>";
echo "<pre>$line2</pre>";
echo "<pre>$line3</pre>";
echo "<pre>$line4</pre>";
echo "<pre>$line5</pre>";
echo "done";
?>

 

The Error it throws me is:-

 

Error(s), warning(s):sh: 1: spawn: not found
sh: 1: expect: not found
sh: 1: send: not found
sh: 1: interact: not found
sh: 1: expect: not found
sh: 1: EOD: not found

 

Any Help will be greatly appreciated.Thanks

Edited by AnkitRauthan
Link to comment
https://forums.phpfreaks.com/topic/305428-issue-in-cpanel-cron-job-php-code/
Share on other sites

Look at the line above.

See it? That means you're in PHP code. Not a shell. And the line later

#!/bin/sh
is entirely misplaced.

 

Either do the work in PHP or don't use PHP at all. The latter is an option since all you're doing with it is spawning processes and showing their output.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.