LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-04-2021, 10:17 PM   #1
schmitta
Member
 
Registered: May 2011
Location: Blacksburg VA
Distribution: UBUNTU, LXLE
Posts: 352

Rep: Reputation: Disabled
need to autorun a program at startup on ubuntu server 21.04


I need to autorun a program at startup on ubuntu server 21.04 . I have worked on this for days with no result. I tried @reboot but it does not work. I tried to look at the logs but did not find anything or error messages. I want to run a bash script (.sh) that cd to a folder and then runs a c program. The machine I am running on is a raspberry pi 3B. it is holding up my project that I need to install. Thank you for your help.
 
Old 05-05-2021, 12:37 AM   #2
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 schmitta View Post
I tried @reboot but it does not work.
"does not work" is never a good problem sdescription.
What exactly did you try there?

What sort of program is this? GUI or no-GUI? What sort of privileges does it require?
...

I believe you are looking for a systemd service.
 
Old 05-05-2021, 08:32 PM   #3
schmitta
Member
 
Registered: May 2011
Location: Blacksburg VA
Distribution: UBUNTU, LXLE
Posts: 352

Original Poster
Rep: Reputation: Disabled
@reboot

I tried:
@reboot sh ~/rpi/startrpi.sh

to get a script to execute

the script is:

#!/bin/bash/
cd ~/rpi
exec ./term

term is a C program that takes what comes in from a USB RS232 and prints it out on tty1

./term does work

I am trying to display information to the user on tty1 after the system boots up

./term is to run continuously while the system is up

maybe I should write a deamon to do this?

thank you for helping me.

Last edited by schmitta; 05-05-2021 at 08:49 PM.
 
Old 05-05-2021, 08:47 PM   #4
schmitta
Member
 
Registered: May 2011
Location: Blacksburg VA
Distribution: UBUNTU, LXLE
Posts: 352

Original Poster
Rep: Reputation: Disabled
This is ubuntu server 21.04 running on a raspberry pi 3B

this is a non gui program
 
Old 05-05-2021, 08:53 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,749

Rep: Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928
cron jobs are not associated with a terminal display and therefore no output will appear regardless if the job runs.

Does the Pi auto login? If so you can start the program from your bash_rc ( I think?)

Last edited by michaelk; 05-05-2021 at 08:54 PM.
 
1 members found this post helpful.
Old 05-06-2021, 12:02 AM   #6
schmitta
Member
 
Registered: May 2011
Location: Blacksburg VA
Distribution: UBUNTU, LXLE
Posts: 352

Original Poster
Rep: Reputation: Disabled
I was able to get it to autologin additional info would be welcome. I will lookup bash_rc
 
Old 05-06-2021, 12:22 AM   #7
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
@michaelk: is the stuff from post #3 recognizable to someone who uses cron?
I understand the basic requirement but I have no idea what OP is on about.
 
Old 05-06-2021, 01:35 AM   #8
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
@ondoho. Well, @reboot is part of crontab specification. It's recognized both by Vixie cron and cronie.
 
Old 05-06-2021, 02:05 AM   #9
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Um. cron doesn’t know from ~ *
Use the absolute path to the script
Code:
@reboot sh /home/user/rpi/startrpi.sh
*well technically it does, but it’s not going to be the same home directory as that in which the script resides.

Last edited by scasey; 05-06-2021 at 02:07 AM.
 
1 members found this post helpful.
Old 05-07-2021, 06:38 AM   #10
schmitta
Member
 
Registered: May 2011
Location: Blacksburg VA
Distribution: UBUNTU, LXLE
Posts: 352

Original Poster
Rep: Reputation: Disabled
I got it to work

I added my script to the end of ~/.bashrc and it executed it and printed on the terminal

i.e.

to /home/ubuntu/.bashrc I added at the end

/home/ubuntu/rpi/startrpi.sh

and the program started to execute. it also executes when I ssh in to the raspberry pi. I
can stop it by cntl+C and then get my work done. Praise GOD!!!!
 
  


Reply

Tags
server, ubuntu 21.04



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
Startup autorun 1veedo Linux - General 2 12-24-2005 08:45 AM
Running autorun daemon on startup basemodel Linux - Software 4 08-20-2004 04:31 PM
boot/startup/autorun commands awejevlen Linux - Newbie 6 05-04-2004 06:52 AM
Stop autorun run at startup digitalbrutus Linux - Software 4 05-02-2004 12:37 PM
autorun a program in tty3 LynX Linux - Newbie 2 11-09-2002 04:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:51 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