decrot
Posts: 10
Joined: Sat Mar 16, 2013 3:47 pm

Automate timelapse

Tue May 21, 2013 3:15 pm

Is there a way to run a bash script without having a user logged in via the raspi itself or through ssh?
I wrote a bash script to take images every few seconds, and run it via ssh, but as soon as I close my putty window, the script stops. I want to be able have a battery pack and take the raspi to various places where lugging a keyboard/monitor is cumbersome and out of wifi range.

gusgriller
Posts: 22
Joined: Thu Nov 24, 2011 1:59 pm

Re: Automate timelapse

Tue May 21, 2013 3:21 pm

I would use a cron job for this. It only has a granularity of a minute, but you could use it to check that the process is running, and if not, fire it up again.

sharix
Posts: 200
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia

Re: Automate timelapse

Tue May 21, 2013 3:22 pm

Yes. Install package "at" and then run:

Code: Select all

at now
> "code you want executed"
Ctrl+D

gusgriller
Posts: 22
Joined: Thu Nov 24, 2011 1:59 pm

Re: Automate timelapse

Tue May 21, 2013 3:25 pm

I was also considering whether there some way of starting scripts from an app on my Android phone, perhaps over bluetooth, but unsuccessful so far. The best I could find was to turn the Pi into a wireless access point and see if I can ssh in that way from my phone. But that would be a bit clunky.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26408
Joined: Sat Jul 30, 2011 7:41 pm

Re: Automate timelapse

Tue May 21, 2013 3:31 pm

Could you use screen to start up a new bash shell that runs continuously after you have logged out? (Just a guess)
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

decrot
Posts: 10
Joined: Sat Mar 16, 2013 3:47 pm

Re: Automate timelapse

Tue May 21, 2013 3:32 pm

jamesh wrote:Could you use screen to start up a new bash shell that runs continuously after you have logged out? (Just a guess)
actually I want something I could write to rc.local to start on boot.

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Automate timelapse

Tue May 21, 2013 3:34 pm

Or you could use a hotspot + a web page to run commands on the Pi ?
decrot wrote:
jamesh wrote:Could you use screen to start up a new bash shell that runs continuously after you have logged out? (Just a guess)
actually I want something I could write to rc.local to start on boot.
cronjob's @reboot could do that
then in the script, just tell it to run itself once it's finished running, or after a sleep of say 5 seconds
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

poing
Posts: 1132
Joined: Thu Mar 08, 2012 3:32 pm

Re: Automate timelapse

Tue May 21, 2013 3:58 pm

SirLagz wrote:Or you could use a hotspot + a web page to run commands on the Pi ?
That's what I do. I also have a web page that refreshes with Ajax when a new image arrives (from an Eye-Fi card for now, but that will work with the PiCamera as well).

Nu7s
Posts: 57
Joined: Wed Jul 25, 2012 9:14 am

Re: Automate timelapse

Tue May 21, 2013 5:12 pm

I created a .sh file with my code:

Code: Select all

#!/bin/bash
sudo raspistill -w 1000 -h 500 -o test%d.jpg -t 18000000 -tl 60000
Made it executable:

Code: Select all

chmod 777 test.sh
And ran it with the command:

Code: Select all

. test.sh &
Runs perfectly fine in the background.

decrot
Posts: 10
Joined: Sat Mar 16, 2013 3:47 pm

Re: Automate timelapse

Wed May 22, 2013 4:50 am

Nu7s wrote:And ran it with the command:

Code: Select all

. test.sh &
Runs perfectly fine in the background.
That's what I needed. Now another question, if I log out, how do I stop the script?

Nu7s
Posts: 57
Joined: Wed Jul 25, 2012 9:14 am

Re: Automate timelapse

Wed May 22, 2013 4:58 am

You should be given a process id. You need to kill that process to stop the script.

Return to “Camera board”