AnkitRauthan Posted October 23, 2017 Share Posted October 23, 2017 (edited) 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 foundsh: 1: expect: not foundsh: 1: send: not foundsh: 1: interact: not foundsh: 1: expect: not foundsh: 1: EOD: not found Any Help will be greatly appreciated.Thanks Edited October 23, 2017 by AnkitRauthan Quote Link to comment https://forums.phpfreaks.com/topic/305428-issue-in-cpanel-cron-job-php-code/ Share on other sites More sharing options...
requinix Posted October 23, 2017 Share Posted October 23, 2017 Your shell is /bin/sh which doesn't have those features. You might be able to do what you want by proc_open()ing /bin/bash and sending the commands through stdin., Or better yet, do the work using PHP. Quote Link to comment https://forums.phpfreaks.com/topic/305428-issue-in-cpanel-cron-job-php-code/#findComment-1552961 Share on other sites More sharing options...
AnkitRauthan Posted October 23, 2017 Author Share Posted October 23, 2017 Yeah,but I'm also using #!/usr/bin/expect.So it should not throw this error Quote Link to comment https://forums.phpfreaks.com/topic/305428-issue-in-cpanel-cron-job-php-code/#findComment-1552962 Share on other sites More sharing options...
requinix Posted October 23, 2017 Share Posted October 23, 2017 Look at the line above. See it? That means you're in PHP code. Not a shell. And the line later #!/bin/shis 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. Quote Link to comment https://forums.phpfreaks.com/topic/305428-issue-in-cpanel-cron-job-php-code/#findComment-1552964 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.