Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Auto start a script

Wed Oct 14, 2015 5:52 pm

as I have some win10 PC issues I'm dealing with.
My sympathies...
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

vacek.fany
Posts: 1
Joined: Wed Oct 14, 2015 5:46 pm

Re: Auto start a script

Wed Oct 14, 2015 6:05 pm

Hi,
I´m beginer,I need some help from more experienced
I want make script for rdesktop
on startup rdesktop working well,connecting to remote desktop ok,
but if remote desktop logout I need something that will watch rdesktop connect to remote desktop, when not - restart rdesktop and reconecting to remote desktop

can someone help me please???

Thank you for time

papjack
Posts: 1
Joined: Mon Jan 18, 2016 10:54 am

Re: Auto start a script

Mon Jan 18, 2016 11:02 am

Well I am having kinda strange poblem /request with my Raspberry Pi.

I wrote a script in Nodejs controlling a Relay over the GPIO Pins...

But that is not my problem, if I start my APP with nodejs myapp.js it is working like a charm.
The Problem or the Issue I have with it is that I want the Raspberry to start, login to the Desktop, so far so good - everything 'till here is working.
But here it comes, I want to autoopen a terminal window and execute my script from there, because I need the App to run in Foreground because of my RFID Reader. I need to scan an RFID and if the App runs in background the App is useless.

Is there a way I ca setup an so called Autoexec.bat for Raspberry so after he logs in with my Username, it opens a Terminal window by itself and executes this script ??? If the script dies on it's way I will still be able to reboot the Pi via SSH.

Thank you guys in advance and best regards

User avatar
RaTTuS
Posts: 10538
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Auto start a script

Wed Feb 03, 2016 12:02 pm

for a script that requires keyboard input / display we have a slightly different service setup ,
let us say that we want to output info and receive keyboard control on a terminal
say tty9 [alt-f9]

using the same procedure as
viewtopic.php?f=29&t=7192&p=828947#p828947
we create the service as

Code: Select all

[Unit]
Description=top test

[Service]
ExecStart=/usr/bin/top
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty9
TTYReset=yes
Restart=always

[Install]
WantedBy=multi-user.target
[this is from memory so I may have to edit]
so when it is installed and enabled
on tty9 top should appear [this can be replaced by your script]
and you should be able to use keyboard commands to control top
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

gllmar
Posts: 2
Joined: Sat Feb 06, 2016 10:56 pm

Re: Auto start a script

Sat Feb 06, 2016 11:01 pm

Thanks a lot for sharing this process, I scouted the internet and the documentation and your tutorial really made my day!

Concerning the script that requires keyboard input / display

How do you access for instance /dev/tty9 over a SSH connection?

Thanks.

User avatar
RaTTuS
Posts: 10538
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Auto start a script

Mon Feb 08, 2016 9:29 am

gllmar wrote:Thanks a lot for sharing this process, I scouted the internet and the documentation and your tutorial really made my day!

Concerning the script that requires keyboard input / display

How do you access for instance /dev/tty9 over a SSH connection?

Thanks.
you don't [well not easily]
what you can do is start of the process in screen and use the screen controls to do stuff
see
man screen
for help
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

gllmar
Posts: 2
Joined: Sat Feb 06, 2016 10:56 pm

Re: Auto start a script

Thu Feb 11, 2016 12:05 pm

Thanks for the insight using screen.

Turn out I read this guide on journalctl and it enlightened my understanding of systemd

https://www.digitalocean.com/community/ ... stemd-logs

Using the -f make the log behave like tail, this way, you can see what is happening in real-time. Bonus, you get free timestamp!

Code: Select all

sudo journalctl -f -u gpioOSC.service 

iandstanley
Posts: 8
Joined: Wed Mar 23, 2016 12:03 pm

Re: Auto start a script

Sat Apr 23, 2016 6:42 pm

bredman wrote: @kernelcode
Putting something into /etc/rc.local adds it to the boot sequence. The word "sequence" is important, if your code gets stuck then the boot sequence cannot proceed. The same with ~/.bashrc, if you put a faulty command in here you may not be able to login.
The way to get around that is to detach the process from the rc script.

Put your code into say my script.sh

Then call (from your rc.local script):

nohup <path-to>/my script.sh &

This will run the script in the background on startup

iandstanley
Posts: 8
Joined: Wed Mar 23, 2016 12:03 pm

Re: Auto start a script

Sat Apr 23, 2016 6:53 pm

iandstanley wrote: The way to get around that is to detach the process from the rc script.

Put your code into say my script.sh

Then call (from your rc.local script):

nohup <path-to>/my script.sh &

This will run the script in the background on startup
And if you need it run as another user try ...

nohup su - pi -c <path>/myscript.sh &

To run it as Pi

iandstanley
Posts: 8
Joined: Wed Mar 23, 2016 12:03 pm

Re: Auto start a script

Sat Apr 23, 2016 6:56 pm

Another option that should work (as Raspbian is based upon Debian):

# crontab -e -u username

@reboot /path/to/shell/script

Never tried it on Raspbian but can't think why it shouldn't work

User avatar
RaTTuS
Posts: 10538
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Auto start a script

Mon Apr 25, 2016 10:10 am

@reboot
works fine [as fine as any other script in cron]
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

gabriel.klein
Posts: 19
Joined: Mon Jul 28, 2014 1:50 pm

Re: Auto start a script

Tue Apr 26, 2016 10:21 am

I use @reboot in a crontab without any issues since years on my raspberry projects :)

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Auto start a script

Thu Oct 13, 2016 11:37 pm

RaTTuS wrote:for a script that requires keyboard input / display we have a slightly different service setup ,
let us say that we want to output info and receive keyboard control on a terminal
say tty9 [alt-f9]

using the same procedure as
viewtopic.php?f=29&t=7192&p=828947#p828947
we create the service as

Code: Select all

[Unit]
Description=top test

[Service]
ExecStart=/usr/bin/top
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty9
TTYReset=yes
Restart=always

[Install]
WantedBy=multi-user.target
[this is from memory so I may have to edit]
so when it is installed and enabled
on tty9 top should appear [this can be replaced by your script]
and you should be able to use keyboard commands to control top
I'm trying to get a headless 20x4 display working with USB keyboard, i can see that the program has started as the display initiates with my welcome text but the keyboard entry doesnt work unless i run the program from the keyboard.

Code: Select all

[Unit]
Description=interactive lcd display

[Service]
ExecStart=/home/pi/dlcd
StandardInput=tty
TTYPath=/dev/tty1
TTYReset=yes
Restart=always

[Install]
WantedBy=multi-user.target
Can anyone advise where i've gone wrong or another methpd of getting keyboard emtry for the display.
Doug.
Building Management Systems Engineer.

User avatar
RaTTuS
Posts: 10538
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Auto start a script

Tue Oct 18, 2016 7:16 am

viewtopic.php?p=921354#p921354 from heater
so I can find this later ;)
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Return to “Advanced users”