LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2017, 06:46 PM   #1
kuhnto
LQ Newbie
 
Registered: Nov 2016
Posts: 8

Rep: Reputation: Disabled
bash script not working as expected when executed at startup


I have the following test script that does not behave as I would expect when I try starting it at boot. My overall script is larger, but this is the essence of the issue at hand. What it is doing is turning on a light (just to verify the script is running), waiting a few seconds, starting a co-process for linphonec, a CLI based SIP phone client, and then sends the "call" command to the co-process for linphone to dial (my cell number replaced with a fake number).
Code:
    #!/bin/bash

    #Turn on the LED Light
    gpio mode 3 out
    gpio write 3 1 

    #sleep
    sleep 5

    #Intial coproc startup for Linphonec
    coproc linphonec
    sleep 4
    echo "call 5555555555" >&"${COPROC[1]}"
    while true
    do
        #[DOES OTHER STUFF HERE]
	    sleep 0.05
    done
I am running this on Raspian as a root user. If I run this from a putty CLI, it works as expected, But my goal is for the script to start at boot. If I put the following in the rc.local and reboot:
Code:
    /usr/local/bin/test.sh &
I see that both the script and linphonec are running:
Code:
    root      1936     1  0 15:26 ?        00:00:00 /bin/bash /usr/local/bin/test.sh
    root      2016  1936  1 15:26 ?        00:00:00 linphonec
The script turns on the light, but the call does not get placed. I am wondering if this has to do with coproc and how it works? I have also tried putting it in a CRON job to start as shown below with the same results:
Code:
    SHELL=/bin/bash
    @reboot /bin/sleep 10 ; /usr/local/bin/test.sh &
The light will turn on, but no call. It is interesting to note that if I kill the script process using "kill", the linphonec process is not killed. If I terminate the process while it is running in a putty terminal using ctrl-c, both processes are stopped.

So how can I get this script to operate correctly at startup? I am sure it has something to do with shells and how they behave, but I do not know much about this.

Last edited by kuhnto; 09-25-2017 at 06:52 PM.
 
Old 09-25-2017, 06:56 PM   #2
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
Bootup script is not running in your user environment, there is no $PATH set, no executables will be found. Meaning if you try to execute foo it wont' be found, you need to execute /full/path/to/foo.
 
Old 09-26-2017, 05:42 AM   #3
kuhnto
LQ Newbie
 
Registered: Nov 2016
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Emerson View Post
Bootup script is not running in your user environment, there is no $PATH set, no executables will be found. Meaning if you try to execute foo it wont' be found, you need to execute /full/path/to/foo.
Are you referring to the coproc call? So it should be "coproc /usr/bin/linphonec"? Both my script and linphonec start up when called from the rc.local, so I am not sure that is the issue. I cal do a ps and see them running. I posted the ps output in my main post.
 
Old 09-26-2017, 05:50 AM   #4
Fergupicus
LQ Newbie
 
Registered: Sep 2017
Posts: 22

Rep: Reputation: Disabled
When I wanted to do this recently I just used cronjob/crontab and put a ./Path/To/Script in the config file.

Hope this helps
-Fergus
 
Old 09-26-2017, 10:43 AM   #5
kuhnto
LQ Newbie
 
Registered: Nov 2016
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Fergupicus View Post
When I wanted to do this recently I just used cronjob/crontab and put a ./Path/To/Script in the config file.
I have tried this too. The same think occurs, the script runs, starts linephonec, but no call. I even put a sleep in the cronjob to ensure the PBX (Running on the same board) is started up before starting the SIP client.

Is there anything special about

Code:
echo "call 5555555555" >&"${COPROC[1]}"
That would not work in a script started without being in a console?

One thing could be that the PBX (IncrediblePBX) that is running on the board has not started fully by the time the script runs, this no call. Would me adding a sleep in the cronjob still allow for the PBX to startup?

Last edited by kuhnto; 09-26-2017 at 10:47 AM.
 
Old 09-26-2017, 11:01 AM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by kuhnto View Post
Are you referring to the coproc call?
no, s/he was refering to everything that is called from your script, every command that is not a shell builtin.
quick glance, i'd say: gpio, coproc.
 
Old 09-26-2017, 01:35 PM   #7
lsalab
LQ Newbie
 
Registered: Jan 2009
Posts: 24

Rep: Reputation: 3
If you have the environment all set up in your root user home directory, you could try to include your bash profile to the beginning of the script. Try to include the '.bashrc' and/or '.profile' from your home directory.

Code:
. /root/.bashrc
or

Code:
. /root/.profile
that should include all the required environment to run the script as if you were running it through putty.
 
Old 09-26-2017, 07:54 PM   #8
kuhnto
LQ Newbie
 
Registered: Nov 2016
Posts: 8

Original Poster
Rep: Reputation: Disabled
Smile

I finally figured out the issue. After I figured out how to generate logs on linphonec, I notice the following on the first line when run from putty:
Code:
ortp-message-Using (r/w) config information from /root/.linphonerc
And When I ran at startup:
Code:
ortp-message-Using (r/w) config information from (null)/.linphonerc
So it looks like it could not get to the config file located in /root. The config file is generated by default if there is not one, so it seemed like it could not read the existing config file (which I had a port change) and looked at a new default one. Without the config file port change, nothing would work. I do not know enough about Linux to know why this was happening. But I ended up putting a new copy of the config in a regular place and now, it can read and work with the new config file at boot.

Thanks everyone!
 
Old 09-26-2017, 08:00 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
coproc is a builtin bash command (as of version 4).

Did you create a proper root account or are you logging in as the default user pi?

Did you create the cronjob as root or pi?

About the only thing I can think of at the moment is that you might want to specify the configuration file in the script.

Code:
coproc linphonec -c /path/to/.linphonec
I see that you already figured it out...

Last edited by michaelk; 09-26-2017 at 08:01 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Commands work if executed one by one in bash terminal but not from script??? taylorkh Linux - General 6 11-12-2011 07:24 AM
Bash script does not behave the same when executed through /etc/rc.local bmpenev Linux - General 1 06-05-2009 11:46 AM
bash script runs different when cron executed jalder85 Linux - Server 4 02-20-2009 11:53 AM
bash script - I want some time delay between each command is executed bbmak Linux - Newbie 2 12-21-2007 03:35 AM
Simple script to be executed on startup. Korff Linux - General 2 06-03-2003 09:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration