LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-17-2007, 06:07 PM   #1
linker3000
LQ Newbie
 
Registered: May 2007
Posts: 9

Rep: Reputation: 0
Running a bash script at startup


Hi,

I have a bash script that reads an image from a security camera every second using wget. At the moment I start the script manually as below. Is it safe to put this startup line in rc.local so that it starts automatically when the server boots? I'd try it now but the server is a long drive away if it goes wrong!

Thanks

Script started with: nohup /root/knapcap.sh &

Script:

# Capture camera image every second
while [ true ]; do
sleep 1
mkdir -p /home/knapcam/$(date +\%Y\%m\%d)/$(date +\%H)
wget --quiet --output-document=/home/knapcam/$(date +\%Y\%m\%d)/$(date +\%H)/knap1_$(date +\%Y\%m\%d\%H\%M\%S).jpg [address of camera]/still.jpg
done
 
Old 05-17-2007, 09:55 PM   #2
fukawi2
Member
 
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Rep: Reputation: 34
Whoops... Correct post comes next....

Last edited by fukawi2; 05-17-2007 at 10:02 PM.
 
Old 05-17-2007, 10:00 PM   #3
fukawi2
Member
 
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Rep: Reputation: 34
Code:
#!/bin/bash

while [ true ]; do
   # Sleep my pretty...
   sleep 1

   # Set our variables for directories and files
   fDir1=`date +\%Y\%m\%d`
   fDir2=`date +\%H`
   fName=`date +\%Y\%m\%d\%H\%M\%S`
   
   # Make the Directory + Download image to it
   mkdir -p /home/knapcam/$fDir1/$fDir2
   wget --quiet --output-document=/home/knapcam/$fDir1/$fDir2/knap1_$fName.jpg [address of camera]/still.jpg
done

exit 0
That should be fine to put in to /etc/rc.local using the nohup and background you posted

I changed it to set the variables of the dates you want and use them when creating directories etc in the extremely unlikely case that the minute ticked over between the mkdir and wget command

And alternative would be to add it to crontab as an @reboot task.

Last edited by fukawi2; 05-17-2007 at 10:02 PM.
 
  


Reply



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
running .pl script on startup knowram Other *NIX 2 03-09-2007 09:50 PM
running su from a bash script caminoix Programming 7 12-28-2005 03:41 PM
Running Perl Script upon startup andy7t Linux - Software 1 04-20-2005 04:43 PM
Running a script at systsem startup logo Linux - Newbie 1 09-21-2004 02:29 PM
where is bash startup script? gvaught Linux - Newbie 6 12-21-2003 05:10 AM

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

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