LinuxQuestions.org
Help answer threads with 0 replies.
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 03-16-2017, 06:26 AM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Rep: Reputation: Disabled
Run script upon boot


Trying to run a c++ script upon boot on a raspberry pi.

I've tried placing it both in /etc/rc.local and using init.d, but no luck.

Then I tried it at the command line, and received an error:
Code:
michael@raspberrypi:/etc/init.d $ /home/michael/cplusclient/build/cplusclient
Failed to open cplusclient.ini, error: No such file or directory
michael@raspberrypi:/etc/init.d $
But this doesn't create an error:
Code:
michael@raspberrypi:/etc/init.d $ cd /home/michael/cplusclient/build
michael@raspberrypi:~/cplusclient/build $ .cplusclient
My current thoughts are to create the following shell script and run it upon boot:
Code:
michael@raspberrypi:/etc/init.d $ cat cplusclient.sh
#!/bin/bash

cd /home/michael/cplusclient/build
cplusclient &

michael@raspberrypi:/etc/init.d $ cat cplusclient
#!/bin/bash
# /etc/init.d/cplusclient

### BEGIN INIT INFO
# Provides:          my client
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: bla bla bla
# Description:       Start my client
### END INIT INFO
#/home/michael/cplusclient/build/cplusclient &
./cplusclient &
michael@raspberrypi:/etc/init.d $
Questions...

Am I generally doing this correct?

Do I need to run both cplusclient and cplusclient.sh in the background or just one of the two? If just one, which one?

EDIT. One more question. How do I deal with the following?

Code:
michael@cplusclient:/etc/init.d $ sudo update-rc.d cplusclient defaults
insserv: warning: script 'cplusclient.sh' missing LSB tags and overrides
michael@raspberrypi:/etc/init.d $
EDIT 2. I think I am just confusing myself. LSB errors are due to not having the appropriate comments/etc. More importantly, why use two files? For some reason, I thought I needed a sh extension on one, but now I am thinking I need to use just cplusclient and put the cd in there...

Thanks

Last edited by NotionCommotion; 03-16-2017 at 06:37 AM.
 
Old 03-16-2017, 08:21 AM   #2
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Can you include the actual script itself?

It looks like you are using a relative link to cplusclient.ini within cplusclient. The script will execute that from where it is, which isn't going to be /home/michael/cplusclient/build/. As you stated adding a cd within the script may work, alternative switching the call to cplusclient.ini from a relative link to an absolute link, should also fix the problem.
 
Old 03-16-2017, 08:23 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 6,883
Blog Entries: 3

Rep: Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575
Code:
#!/bin/bash
# /etc/init.d/cplusclient

### BEGIN INIT INFO
# Provides:          my client
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: bla bla bla
# Description:       Start my client
### END INIT INFO
#/home/michael/cplusclient/build/cplusclient &
./cplusclient
You are missing the absolute path to the script cplusclient. That might be one of the problems.
 
Old 03-16-2017, 08:36 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,413

Rep: Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540
Quote:
Originally Posted by Turbocapitalist View Post
You are missing the absolute path to the script cplusclient. That might be one of the problems.
Specifying the absolute path won't fix it, the issue is that whatever "cplusclient" does it looks like it's attempting to look for its ini file in the folder it's called from, so the OP will need "cd /home/michael/cplusclient/build" in the script before attempting "./cplusclient"
 
Old 03-16-2017, 08:12 PM   #5
X-LFS-2010
Member
 
Registered: Apr 2016
Posts: 510

Rep: Reputation: 58
cat cplusclient.sh does a cd then runs ./cplusclient

but your init.d script (does that work with systemd?) tries to run cplusclient, not cplusclient.sh, and cat cplusclient is NOT in the PATH (and you didn't set the PATH= either)

what i see is a simple error that you commented out "cd path" in init.d/cplusclient and aren't trying to run cplusclient.sh in init.d/cplusclient
 
  


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
[SOLVED] Run script on first boot bmp99 Linux - Server 6 12-26-2013 12:42 PM
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 08:15 PM
Can't get script to run on boot Ook Slackware 7 03-05-2005 01:31 AM
Script to run at boot robbow52 Debian 17 09-03-2004 09:04 PM
Getting script to run at boot Andy@DP Linux - Newbie 4 06-05-2004 07:39 AM

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

All times are GMT -5. The time now is 06:20 PM.

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