0

I am executing s3cmd command with shell_exec in php. Everything is working fine . Only thing is how to send an email when the s3cmd process is finished. I am trying the below code

shell_exec('export HOME="";s3cmd -c /home/.s3cfg ls email@yahoo.com > /dev/null 2>/dev/null &');

Any idea to solve this issue

hakre
  • 193,403
  • 52
  • 435
  • 836
Anish
  • 4,262
  • 6
  • 36
  • 58
  • Why not just sending a mail in next line via `mail()`? – Hecke29 Apr 04 '14 at 09:21
  • Funny, when you type 'PHP shell_exec' into Google, it automatically adds 'wait until finished', leading you to numerous answers, like [this one](http://stackoverflow.com/questions/7621348/how-to-execute-shell-commands-synchronously-in-php). – GolezTrol Apr 04 '14 at 09:22
  • Yeah check the exit status and then send the email. – va5ja Apr 04 '14 at 09:22
  • The shell command is run in the background (with `&`) - I'm not sure whether by the time the function returns the underlying shell command will have finished. – Aleks G Apr 04 '14 at 09:23
  • @va5ja `shell_exec` does not provide access to the exit status – Aleks G Apr 04 '14 at 09:23
  • @AleksG Yes I am trying to do this as a background job why because cloud sync will take a lot of time to get synced with s3 . Same time I need to process request of multiple user. So I was hoping putting as a background job will work as expected. – Anish Apr 04 '14 at 09:27
  • @aneesh: Then use exec(). – va5ja Apr 04 '14 at 09:28
  • @va5ja According to you (sorry If I am wrong) write mail function next to exec correct ? If yes user has to wait for a long time on that page. That why I am adding it to background job. Is there any way to send email from that command? – Anish Apr 04 '14 at 09:33
  • @aneesh: I understand. Well you could pipeline the two commands with &&, running the second command (sending email) only if the first command finished successfully. – va5ja Apr 04 '14 at 09:48
  • @va5ja Thank you for replying . If you don't mind can you please write it – Anish Apr 04 '14 at 10:02
  • @aneesh: Well something along `s3cmd ... && /bin/mail ... &`. You can use sendmail etc or just exec some cli php script. – va5ja Apr 04 '14 at 10:08

0 Answers0