Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: Bash script : parent / child process issue ?

  1. #11
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    21,054
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Bash script : parent / child process issue ?

    Perhaps if I ask for information a different way? Descriptions show what you think is happening, not necessarily what actually is happening.

    What do you think we need to see to help you?

  2. #12
    Join Date
    Jun 2018
    Beans
    Hidden!

    Re: Bash script : parent / child process issue ?

    I don't know. I will try something else indeed: isolating a minimal script and post it with all command used on bash and cron. My script is probably too complex to explore line by line what could play up.

  3. #13
    Join Date
    Jun 2018
    Beans
    Hidden!

    Re: Bash script : parent / child process issue ?

    Here is my crontab:

    Code:
    crontab -l | { cat; echo "*/1 * * * * pgrep -f test6 > /dev/null || ~/Documents/Linux/test6"; } | crontab -
    which works partially. Started this way, only the "cp" command of the following script works, "bin1 test" doesn't start.

    My test script is now this (for test purpose):

    Code:
    #!/bin/bash
    
    # to check if script works
    cp /etc/os-release /home/mohicann/os-release
    
    # to start test
    /home/mohicann/bin1 test >> ~/data.txt

    - If "bin1 test" is launched from console alone, it works.

    Parent is "bash".


    - If my script "test6" is launched from console, everything works.

    "test6": parent is "bash".
    "bin1 test": parent is "test6".


    - If my script "test6" is launched from double-click, everything works as well.

    "test6": parent is "dolphin".
    "bin1 test": parent is "test6".


    If all cases, everything works: os-release is copied and/or "bin1 test" sends its data to data.txt.

    When I shut down my script test6, bin1 is still running, but no longer provides data to data.txt. Moreover it's parent becomes systemd.

  4. #14
    Join Date
    Jun 2018
    Beans
    Hidden!

    Re: Bash script : parent / child process issue ?

    PS: even with this crontab, it doesn't work:

    Code:
    crontab -l | { cat; echo "*/1 * * * * /home/user/bin1 test >> /home/user/data.txt"; } | crontab -
    But if I remove "bin1 test" from my script, even this crontab works (it copies os-release each minute):

    Code:
    crontab -l | { cat; echo "*/1 * * * * ~/test6"; } | crontab -
    Last edited by mohicann; June 7th, 2018 at 08:21 PM.

  5. #15
    Join Date
    Jun 2018
    Beans
    Hidden!

    Re: Bash script : parent / child process issue ?

    Even when correcting my script, it still doesn't work :

    Code:
    #!/bin/bash
    
    # to check if script works
    cp /etc/os-release /home/mohicann/os-release
    
    # to start test
    /home/mohicann/bin1 test >> /home/mohicann/data.txt
    Last edited by mohicann; June 7th, 2018 at 08:20 PM.

  6. #16
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,545
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Bash script : parent / child process issue ?

    Maybe bin1 is seg-faulting or something like that. Try:
    Code:
    #!/bin/bash
    
    # to check if script works
    cp /etc/os-release /home/mohicann/os-release
    
    # to start test
    ulimit -c unlimited
    /home/mohicann/bin1 test >> /home/mohicann/data.txt
    If it is seg-faulting you should get a core in your home directory, which you can then debug with gdb and get a backtrace.

  7. #17
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,796
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Bash script : parent / child process issue ?

    It looks like 'bin1' might need environment vars to run. These are usually given by an interactive shell, or the desktop.

    Try this:
    Code:
    #!/bin/bash
    
    source ~/.profile
    
    # to check if script works
    cp /etc/os-release /home/mohicann/os-release
    
    # to start test
    /home/mohicann/bin1 test >> /home/mohicann/data.txt
    This would force the execution of ~/.bashrc too.

    If 'bin1' needs a graphical environment, you need an extra variable at the crontab level:
    Code:
    crontab -l | { cat; echo "*/1 * * * *  pgrep -f test6 > /dev/null || env DISPLAY=:0 ~/Documents/Linux/test6"; } | crontab -
    You may want to use DISPLAY=:0.0 if you have a multiple monitor setup.

    Hope it helps. Let us know how it goes.
    Regards.

  8. #18
    Join Date
    Jun 2018
    Beans
    Hidden!

    Re: Bash script : parent / child process issue ?

    Thank you very much for your replies.

    Quote Originally Posted by spjackson View Post
    Maybe bin1 is seg-faulting or something like that. Try:
    Code:
    ulimit -c unlimited
    If it is seg-faulting you should get a core in your home directory, which you can then debug with gdb and get a backtrace.
    I keep this as I've already had a seg-faulting message on another setup, I may need it to solve that one day or another.


    Quote Originally Posted by papibe View Post
    It looks like 'bin1' might need environment vars to run. These are usually given by an interactive shell, or the desktop.

    Try this:
    Code:
    #!/bin/bash
    
    source ~/.profile
    
    # to check if script works
    cp /etc/os-release /home/mohicann/os-release
    
    # to start test
    /home/mohicann/bin1 test >> /home/mohicann/data.txt
    This would force the execution of ~/.bashrc too.
    It worked! Well done! I'll check everything to ensure there is nothing left, but at least the stubborn process eventually gave up... Now its starts and provides its data when launched from cron!

    Thank you very much all for your help!
    Last edited by mohicann; June 7th, 2018 at 11:56 PM.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •