Waiting for a script completion


Last Updated: 2012-10-31 11:33:49
  1. Vampirex

    Vampirex Active Member

    Hello All,
    I am facing a small, but annoying trouble: every week I start an automated backup (with ONandroid) with a Tasker profile triggered by power plugged, date and time. After the task ends, I send me a notification and an email as a report of the operation. All could work very well, but unfortunately, the Tasker task ends before the end of the SL4A script (which is a shell script), so I am unable to send the log file with as embedded file to the email.
    Can someone tell how to force Tasker to wait for the script completion before sending the email ?
    Many thanks.
    Best regards.
    Daniel.

    Advertisement
  2. bberryhill0

    bberryhill0 Well-Known Member

    Can you set a variable at the end of the script that Tasker waits for?
  3. Vampirex

    Vampirex Active Member

    I don't know if it is possible. Is a variable to be set in the shell, can be seen by Tasker ? Otherwise it could be a good solution. The communication between Android environment and Tasker is not very clear for me.
    BR.
    Daniel.
  4. bberryhill0

    bberryhill0 Well-Known Member

    I don't know scripts. You could also have Tasker wait for however many seconds it takes the script to finish.
  5. Vampirex

    Vampirex Active Member

    Yes, it is what I have done. But in case of problem in the backup operation, the result is unpredictable, so it is not a good solution.
    I looked in the user guide, but it doesn't seem to have any cross environment facility in Tasker.
    There is a reference to %CLIP (clipboard) but I cannot use it, as it appears in the user manual, but not usable in the running product.
    BR.
    Daniel.
  6. SUroot

    SUroot Well-Known Member Developer

    I'm assuming if it ends before the script finishes, your context is event > power?

    I would recommend state > power. That way the profile remains active until state is no longer true.

    Then you can send the email as an exit task
  7. Vampirex

    Vampirex Active Member

    It is exactly what I do, but the task is finished in a very short time and it takes about 10 minutes to the full backup. I send a notification and an email as an exit task and they are both sent before the end of the script, so it doesn't work.
    I wonder if the problem isn't that Tasker starts the SL4A script, but as it seems there is no kind of sync mechanism, the script is ended when the task is launched. A related problem is that I don't see any way to get a return code from the script execution.
    Any idea ?
    BR.
    Daniel.

    PS: I have checked in removing the 15 minutes delay I used before sending email, I confirm that the task is ended as soon as the script is launched.
  8. SUroot

    SUroot Well-Known Member Developer

    Can you export the profile as xml and upload it please? And the script minus your email address?
  9. Vampirex

    Vampirex Active Member

    Hello,
    Yes, of course.
    Enclosed is a TaskerBackup.zip file containing:
    -the profile with the 15 minutes delay, named 'DP.Backup.auto.prf.xml',
    -the SL4A script (calling proc) is 'Call.DPonandroid.sh', (in fact I renamed it as it is also called DPonandroid),
    -and the script itself (which is located on the external card (extSdCard) called 'DPonandroid.sh'.
    BR.
    Daniel.

    PS I replaced my email address by "mymail".

    Attached Files:

  10. SUroot

    SUroot Well-Known Member Developer

    Thanks. I'll have a look tonight if I get chance.
  11. SUroot

    SUroot Well-Known Member Developer

    Have you tried the following????


    Profile 1
    Context - Power connect
    Task - run backup

    Profile 2
    Context - File modified > mnt/extSdCard/clockworkmod/backup/DPbackupauto/onandroid.txt
    Task - Email file
  12. Vampirex

    Vampirex Active Member

    It should work, but I wouldn't have any feed back if the backup doesn't go as it should and the file is not recreated, I wouldn't get any email. I stayed 15 days without backup, because my upgrade to JB 4.1.1 was rather 'manly' and I didn't see nothing because my proc had stopped running and I no longer got the backup email. I would be happy to find a way to get the return code from the script. Is it possible to post something like a 'Event Control Block' to communicate a status between asynchronous tasks ? (Remember I am a newbie in Android)!!!
    BR.
    Daniel.
  13. SUroot

    SUroot Well-Known Member Developer

    I really don't know the answer to that. You may need help ftothe tasker dev.

    I don't fully understand the requirement though. You need a failure email too? I thought not receiving backup success email indicated failure.

    Maybe you could describe exactly what you want to happen please. Not in terms of tasker but in terms of actual events.
  14. SUroot

    SUroot Well-Known Member Developer

    Looking at your script, you have many echo.

    Each echo instead could output to a different file name. You could have multiple profiles waiting for multiple files to be edited and a task for each outcome
  15. Vampirex

    Vampirex Active Member

    Very easy, here is the full procedure:
    -Every Sunday at 2h AM and if the device is powered on, I start a ONandroid Backup. To do so I rename the last backup folder to "old backup".
    -The backup run and creates new folder containing different files following Nand backup rules. At the end, I copy the log file renamed in .txt in the new backup folder.
    -Then, I send a notify msg and an email with the log file enclosed. As soon as l get the email, I can read the log file and I know immediately (generally Sunday in the morning ) if the backup is OK.

    What I initially wanted is, like on any Unix system or Mainframe (IBM MVS, VM...), be informed with a return code if something is wrong (generally 0 is OK, everything else requires attention). In this case you can send an alert or email, abort the script, execute a program or everything you want.
    Unfortunately I was not able to synchronise all these actions and I chose to send the email. But as the Tasker task ends before the backup program, it is sent before the end of the backup, so I introduced a 15 minutes wait time because the backup duration is about 11 minutes and it works. But if for any raison, the backup is longer, it will not work.
    My theory is that (very often confirmed by facts) all has to be automatic, specifically in terms of backup. You should be warned only if something is wrong.
    Is it clear ?
    I had used my good backup when I moved to JB 4.1.1....
    BR.
    Daniel.
  16. Vampirex

    Vampirex Active Member

    I am trying to work with files events, but up to now, no success.
    But on the SGS3 there is a problem as the internal storage is called "sdcard" and the real one is "extSdCard", I have encountered serious trouble with that, so unable to have something working with Tasker file events.
    BR.
  17. SUroot

    SUroot Well-Known Member Developer

    Well actually anything you set on /sdcard will need updating to /sdcard0 on the s3 once you have jellybean.

    Anyway, shouldn't have any issue with /sdcard /extSdCard. You browse the file not type it. No problems
  18. Vampirex

    Vampirex Active Member

    If you use sdcard0 you have to use /storage/sdcard0/.
    Is it a problem with /mnt/sdcard/ ?
    BR.
    Daniel.
  19. SUroot

    SUroot Well-Known Member Developer

    When I browse its /storage/sdcard0.

    Actually you're right, /storage/extSdCard doesn't want to work but I can trigger from file mod from /storage/sdcard0/bump.txt for example...

    I really think you need the dev's help on this.
  20. Vampirex

    Vampirex Active Member

    What do you mean by "I really think you need the dev's help on this."?
    BR.
    Daniel.
  21. SUroot

    SUroot Well-Known Member Developer

    The developer of Tasker. You need his help.
  22. Vampirex

    Vampirex Active Member

    Tasker doesn't work very well, in the file area, I mean it is not reliable.
    I have done at least 70 tests with all the forms available (deleted, modified, opened, closed, moved): some don't work at all, some others work sometime, but sometime don't. I think this function is not usable. I have tried to send my email with another method: 'mail' or 'mutt' command, but they are not supported by Android.
    BR.
    Daniel.
  23. Vampirex

    Vampirex Active Member

    Hi,
    I think that I fixed the problem. Rather than using file action, I used the test function with filename. It was a little more complicated as before but it seems to be reliable. Tasker always give the right data in this way.
    Anyway, thank you for trying to help me.
    BR.
    Daniel.

    PS: tell me if you are interested as I can upload to share.
  24. bberryhill0

    bberryhill0 Well-Known Member

    Interested. Let us know more about how you did it!
  25. Vampirex

    Vampirex Active Member

    Well, it is not very difficult.
    I trigger starting the Tasker profile by day of the week, time, and power plugged device .
    In the shell script, I begin by housekeeping in my folders, then I launch the Onandroid command, and when the backup ends I copy the log file in my backup folder.
    Now, in the Tasker profile, what I want is to wait for backup completion and sending an alert (positive if OK, negative if wrong). So I need to have something telling me if the shell backup script is completed. I chose to test the last file closed, indeed it is the log file, as in the shell script, I copy it myself to the backup folder.
    To do that I have a loop (set to one minute) on a filename test. It means every minute I test if the file exists (this is a reliable Tasker function), if no, I launch to another loop, if yes the backup is finished. Then, I send a notification in the notification area and I eMail me the log file.
    In addition, if the loop counter goes more than 20 (20 minutes), the backup has probably encountered some troubles, so I stop the task, post a notification and send a negative eMail without the log file, but indicating where to find the original log file (probably not closed).
    With this method I am even able to communicate with a Tasker task as I can insert anything I want (return code

    Attached Files:

    bberryhill0 likes this.

Share This Page