"Os_execute" does not execute the .sh file

  • Hello,


    How does it happen that the "os_execute" statement does not execute my send_mail.sh file in its entirety?


    That's crazy!


    Explanations: I have a file send_mail.sh whose contents are as follows:
    -----------------

    Code
    #!/usr/bin/env bash
    echo " " > /home/pi/doorpi/mail.txt
    echo  "On a sonné à la porte!"  > /home/pi/doorpi/mail.txt
    echo  "Date: " `date`  >> /home/pi/doorpi/mail.txt
    cat /home/pi/doorpi/mail.txt | mutt -s "il y a quelqu un à la porte!" xxxxxxxxx@orange.fr


    The first echo deletes the text file mail.txt.
    The second echo put the text "We rang the door!" In the text file mail.txt.
    The third echo sets the date in the text file mail.txt.
    The cat (with mutt) statement must send the contents of the mail.txt file to the e-mail address xxxxxxxxx@orange.fr


    Now in doorpi.ini, the "os_execute" statement does not execute my file send_mail.sh:


    Code
    [keyboards]
    onboardpins = gpio 
    
    
    [onboardpins_InputPins]
    11 = sleep:0 
    
    
    [EVENT_OnKeyUp_onboardpins.11]                         
    30 = os_execute:/home/pi/doorpi/envoi_mail.sh

    I do not receive the message in my mail xxxxxxxxx@orange.fr
    While the sending date appears in the mail.txt file.


    Does anyone understand something?


    My file send_mail.sh works because when I click on it (on the file sendmail.sh) I send and I receive the message in my mail.


    For me Doorpi does not execute the cat command.


    If someone has an idea...


    Cordially.


    Pat

  • 1: I did not understand what you meant
    2 and 3: I reassure you: sudo works in a script bash the equivalent of a terminal (console). This is why the program starts with: #! / Usr / bin / env bash. If I run the program send_mail.sh with sudo to all lines, it works. On the other hand, if it is integrated in doorpi.ini, only the line "cat ..." does not give the message (does not work). And, there is no error display on the screen.

  • Hello,


    Sorry but i tried the shell bash, sh ... The file send_mail.sh does not work with os-execute in doorpi.ini.


    That's crazy.


    I use in my file send_mail.sh a few lines of the file doorpi_email.sh https://www.doorpi.org/forum/thread/296-doorpi-von-han-solo/ membre de la Han Solo et il ne fonctionne pas.


    Are there specific rights in doorpi?
    (Other than do: chmod + x /home/pi/Doorpi/envoi_mail.sh before running doorpi for it to be executable)

  • I searched the shell on my Raspberry Pi behind the pi user name with:


    Pi @ raspberrypi: ~ $ cat / etc / passwd | Cut -d: -f1,7 | Grep pi
    Pi: / bin / bash


    Following this, I put "#! / Bin / bash" at the beginning of my file send_mail.sh.


    I also looked for the existence of the cat command with:


    Pi @ raspberrypi: ~ $ which -a cat


    My RASPBERRY Pi gave me:


    Pi @ raspberrypi: ~ $ which -a cat
    / Bin / cat


    And I added / bin / front cat in my file send_mail.sh.


    Nothing makes it: it does not work


    I even searched the mutt path with:


    Pi @ raspberrypi: ~ $ which -a mutt
    / Usr / bin / mutt


    My file send_mail. Sh looks like this:

    Bash
    #!/bin/bash
    
    
    echo " " > /home/pi/Doorpi/mail.txt
    echo  "On a sonné à la porte!"  > /home/pi/Doorpi/mail.txt
    echo  "Date: " `date`  >> /home/pi/Doorpi/mail.txt
    
    
    /bin/cat /home/pi/Doorpi/mail.txt | /usr/bin/mutt -s "il y a quelqu un à la porte!" xxxxxxxxx@orange.fr

    And it does not work in doorpi!


    I will soon throw in the towel.

  • Hm, instead of working systematically, you are simply trying to do the same thing all over again. I think I know what goes wrong - but you should try this for yourself:


    1. question: Is the file /home/pi/Doorpi/mail.txt generated properly ?
    2. try to execute /bin/cat /home/pi/Doorpi/mail.txt > /home/pi/Doorpi/mail.copy from DoorPi. Is the file ...mail.copy generated properly ? If yes, by which user, e.g., who owns it ?


    3. try to execute /bin/cat /home/pi/Doorpi/mail.txt | tee > /home/pi/Doorpi/mail.copy2 from DoorPi. Is the file ...mail.copy2 generated properly ? If yes, by which user, e.g., who owns it ?


    Regards


    pah

  • Hello Pah and thank you for your reply.


    1. Yes, the /home/pi/Doorpi/mail.txt file is generated correctly.
    Its contents are: Date: Sunday 19 March 2017, 10:14:13 (UTC + 0100)


    2. I ran in the console: / bin / cat /home/pi/Doorpi/mail.txt> /home/pi/Doorpi/mail.copy
    The mail.copy file is generated correctly. Its contents are identical: Date: Sunday 19 March 2017, 10:14:13 (UTC + 0100)


    The files belong to pi:


    Pi @ raspberrypi: ~ / Doorpi $ ls -l
    -rw-r-r- 1 pi pi 75 March 19 10:14 mail.txt
    -rw-r-r- 1 pi pi 75 March 20 14:45 mail.copy


    3. I ran in the console: / bin / cat /home/pi/Doorpi/mail.txt | Tee> /home/pi/Doorpi/mail.copy2
    The file mail.copy2 is generated correctly. Its context is identical: Date: Sunday 19 March 2017, 10:14:13 (UTC + 0100)


    The files belong to pi:


    Pi @ raspberrypi: ~ / Doorpi $ ls -l
    -rw-r-r- 1 pi pi 75 March 19 10:14 mail.txt
    -rw-r-r- 1 pi pi 75 March 20 14:45 mail.copy
    -rw-r-r- 1 pi pi 75 March 20 14:51 mail.copy2


    I also integrated the 2 lines in my file send_sh :


    Bash
    #!/bin/bash
    
    
    echo  "Date: " `date`  >> /home/pi/Doorpi/mail.txt
    /bin/cat /home/pi/Doorpi/mail.txt> mail.copy
    /bin/cat /home/pi/Doorpi/mail.txt | tee> mail.copy2


    The launch of this file in a terminal works.



    But integrated in doorpi.ini behind "os_execute", it does not work: the 2 files mailcopy and mail.copy2 are not created.
    Only the mail.txt file is updated


    What is your conclusion?


    In waiting, thank you. cordially


    Pat

  • Is there anyone who has the solution?


    Here I dry: it may be an internal doorpi problem, a rights issue (but I doubt it because my txt file is updated)
    Or it lacks an import in my file bash (but there I do not have the skills)


    Ideas?


    Pat


    For information: I have updated by: update, upgrade, dist-upgrade and rpi_update. And, I always have the same thing

  • Hi, script has to be in basepath.
    In the following example: /usr/local/etc/DoorPi/scripts/doorpi_email.sh


    doorpi.ini (Schnipsel)


    Code
    [DoorPi]
    base_path = /usr/local/etc/DoorPi
    
    
    [EVENT_OnKeyDown_onboardpins.11]
    10 = call:**623
    20 = os_execute:!BASEPATH!/scripts/doorpi_email.sh


    doorpi_email.sh

  • Hello Han-solo,


    Thank you for your answer: I did not know for! BASEPATH !.
    We learn every day!


    For my part, it does not work. I do not know why!


    To understand, I have minimized things:


    My doorpi is like you:

    Code
    [DoorPi]
    base_path = /usr/local/etc/DoorPi
    
    
    [EVENT_OnKeyDown_onboardpins.11]
    10 = os_execute:!BASEPATH!/scripts/envoi_mail.sh

    And my file send_mail.sh is minimalist such as:

    Bash
    #!/bin/bash
    echo " " > /home/pi/Doorpi/mail.txt
    echo  "On a sonné à la porte!"  > /home/pi/Doorpi/mail.txt
    echo  "Date: " `date`  >> /home/pi/Doorpi/mail.txt
    cat /home/pi/Doorpi/mail.txt | mutt -s "y a quelqu'un!" xxxxxxxxx@orange.fr

    Except DOORPI, this executable file works: it sends the message in my box orange.fr


    In DOORPI after:
    Pi @ raspberrypi: ~ $ sudo /etc/init.d/doorpi start


    And press button, I do not receive any message in my mailbox. I do not understand why!


    Do you use the parameters of the .muttrc file?


    In the waiting, thank you.


    Cordially.


    Pat

  • Hello Streicher,


    The directory (full path) is my file send_mail.sh is:
    /usr/local/etc/DoorPi/scripts/


    Why?


    The rights are:


    Pi @ raspberrypi: ~ $ ls -l /usr/local/etc/DoorPi/scripts/envoi_mail.sh
    -rwxr-xr-x 1 root staff 468 Mar 27 19:22 /usr/local/etc/DoorPi/scripts/envoi_mail.sh


    Pat

  • Because the directory could be wrong, but looks good.
    However, give it a try if you use:


    Code
    10 = os_execute:/usr/local/etc/DoorPi/scripts/envoi_mail.sh

    And as pahenning already wrote. Maybe there is a problem with the user which want to execute the script.
    e.g. try first some simple things in the script like "/usr/bin/touch /tmp/mytestfile" and look if the mytestfile exists than you now the script was executed. This simple example should be possible from all users.

  • In doorpi.ini, I wrote:

    Code
    10 = os_execute:/usr/local/etc/DoorPi/scripts/envoi_mail.sh


    In send_mail.sh, I wrote:


    Bash
    #!/bin/bash
    /usr/bin/touch /tmp/mytestfile

    => After starting DOORPI and pressing the button, the file mytestfile was created in tmp.
    We know that it works.


    Then, in send_mail.sh, I wrote:


    Bash
    #!/bin/bash
    echo " " > /home/pi/Doorpi/mail.txt
    echo  "On a sonné à la porte!"  > /home/pi/Doorpi/mail.txt
    echo  "Date: " `date`  >> /home/pi/Doorpi/mail.txt

    => After starting DOORPI and pressing the button, the mail.txt file was created in / home / pi / Doorpi /.
    Again, we know that it works.


    Then, still in send_mail.sh, I wrote:


    Bash
    #!/bin/bash
    echo " " > /home/pi/Doorpi/mail.txt
    echo  "On a sonné à la porte!"  > /home/pi/Doorpi/mail.txt
    echo  "Date: " `date`  >> /home/pi/Doorpi/mail.txt
    cat /home/pi/Doorpi/mail.txt> mail.copy1
    cat /home/pi/Doorpi/mail.txt | tee> mail.copy2
    cat /home/pi/Doorpi/mail.txt | mutt -s "y a quelqu'un!" xxxxxxxxx@orange.$

    => After starting DOORPI and pressing the button, the file mail.txt is created in / home / pi / Doorpi / with the 3 commands "echo"


    But the 3 lines "cat" give nothing.

  • I added in my send_mail.sh scrypt: / bin / cat and / usr / bin / mutt (for cat and mutt) such as:


    Bash
    #!/bin/bash
    echo " " > /home/pi/Doorpi/mail.txt
    echo  "On a sonné à la porte!"  > /home/pi/Doorpi/mail.txt
    echo  "Date: " `date`  >> /home/pi/Doorpi/mail.txt
    
    
    /bin/cat /home/pi/Doorpi/mail.txt> mail.copy1
    /bin/cat /home/pi/Doorpi/mail.txt | /usr/bin/tee> mail.copy2
    /bin/cat /home/pi/Doorpi/mail.txt | /usr/bin/mutt -s "y a quelqu'un!" xxxxxxxxxx@orange.fr

    After launching DOORPI (with start) and pressing the button, the line '... cat ... mutt ...' still does not work.


    Only "echo" lines and the first 2 lines "... cat ..." work: the mail.txt file is updated and the test files mail.copy1 and mail.copy2 are created .

  • Hello everyone,


    At the request of Thomas, I issued the following command:

    Code
    Pi @ raspberrypi: ~ $ / usr / bin / python /usr/local/etc/DoorPi/main.py start --configfile /usr/local/etc/DoorPi/conf/doorpi.ini --trace
    > / Usr / bin / python: can not open file '/usr/local/etc/DoorPi/main.py': [Errno 2] No such file or directory


    I then search the file main.py of DOORPI with the command:

    Code
    Pi @ raspberrypi: ~ $ sudo find / -name main.py
    /usr/local/lib/python2.7/dist-packages/doorpi/main.py
    /usr/share/geany/templates/files/main.py
    /usr/lib/pypy/lib-python/2.7/unittest/main.py
    /usr/lib/pypy/lib-python/2.7/lib2to3/main.py
    /usr/lib/python2.7/unittest/main.py
    /usr/lib/python2.7/lib2to3/main.py
    /usr/lib/python3.4/unittest/main.py
    /usr/lib/python3.4/lib2to3/main.py
    Pi @ raspberrypi: ~ $

    I've launched the command with: /usr/local/lib/python2.7/dist-packages/doorpi/main.py
    This gives:


    Code
    Pi @ raspberrypi: ~ $ / usr / bin / python /usr/local/lib/python2.7/dist-packages/doorpi/main.py start --configfile /usr/local/etc/DoorPi/conf/doorpi.ini --trace
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/doorpi/main.py", line 10, in <module>
        Import doorpi
      File "/usr/local/lib/python2.7/dist-packages/doorpi/doorpi.py", line 19, in <module>
        From keyboard.KeyboardInterface import load_keyboard
      File "/usr/local/lib/python2.7/dist-packages/doorpi/keyboard/KeyboardInterface.py", line 11, in <module>
        From doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass
    ImportError: No module named keyboard.AbstractBaseClass
    Pi @ raspberrypi: ~ $

    Pat

  • I inform you that I finally managed with DOORPI to send me a message with an attachment with the command "... cat ... mutt ..."


    In fact, you must force mutt to use the .muttr file


    Here is the command to integrate in the file send_mail.sh:


    / Bin / cat /home/pi/Doorpi/mail.txt | / Usr / bin / mutt -F /home/pi/.muttrc -s "There's someone!" -a /home/pi/Doorpi/message_absence.wav - xxxxxxx@orange.fr


    Thanks again to all the participants.


    PatI


    PS : nteresting link is on MUTT : http://cedricduval.free.fr/mutt/en/sitehtml/manual-6.html