LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-30-2013, 08:17 AM   #1
mahachi
LQ Newbie
 
Registered: May 2013
Posts: 3

Rep: Reputation: Disabled
script on boot


i have a script that calls a program on boot and it works fine.
Code:
#! /bin/sh
# /etc/init.d/myCode

### BEGIN INIT INFO
# Provides:          myCode
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       This simple script calls to /home/pi/myCode
### END INIT INFO

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    # run application you want to start
    /home/pi/myCode
    ;;
  stop)
    # kill application you want to stop
    killall myCode
    ;;
  *)
    echo "Usage: /etc/init.d/myCode {start|stop}"
    exit 1
    ;;
esac

exit 0
what can i do to delay this script from running for example 50 seconds?
 
Old 05-30-2013, 08:20 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,680

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
Quote:
Originally Posted by mahachi View Post
i have a script that calls a program on boot and it works fine.

what can i do to delay this script from running for example 50 seconds?
Have you tried putting "sleep 50" at the top of the script?
 
Old 05-30-2013, 08:46 AM   #3
mahachi
LQ Newbie
 
Registered: May 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
yes, i have tried that and its not what i am looking for. Sleep only pauses execution and nothing happens until time's up. I want this script to run after everything else after startup
 
Old 05-30-2013, 08:59 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,680

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
Quote:
Originally Posted by mahachi View Post
yes, i have tried that and its not what i am looking for. Sleep only pauses execution and nothing happens until time's up. I want this script to run after everything else after startup
Ok...so why doesn't it do what you want? If you put "sleep 50" at the very top of the script, the script will start...but no other processing will go on until the timeout is reached, essentially doing what you want.

If you want it to start after a particular service, then you can just call the script from the bottom of that service's startup script, or put a link in whatever runlevel directory you want at the very end. For example, if your default runlevel is 3, look in /etc/rc3.d...you'll see scripts named things like S50cups and K50cups. Those are to Start or Kill a process. If you want it to run AFTER, create a symbolic link to your script named something like "S51<your script>". After ALL of the S50's are started, then S51 will start.
 
Old 05-31-2013, 03:18 AM   #5
mahachi
LQ Newbie
 
Registered: May 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
yes, adding a sleep in the script is not yielding desired rusults.

myCode opens a file sored on a computer, reads whats in that file and sends to the serial port. when i put myCode script on start up, it gives an error "File not found" which means the code was executed on startup before it could get access to all the files stored on the comuputer. So, basically i am looking for a way to delay script and run it when all the files are accessible.......After start up...



Quote:
If you want it to start after a particular service, then you can just call the script from the bottom of that service's startup script, or put a link in whatever runlevel directory you want at the very end. For example, if your default runlevel is 3, look in /etc/rc3.d...you'll see scripts named things like S50cups and K50cups. Those are to Start or Kill a process. If you want it to run AFTER, create a symbolic link to your script named something like "S51<your script>". After ALL of the S50's are started, then S51 will start.
its not working...
 
Old 05-31-2013, 08:57 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,680

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
Quote:
Originally Posted by mahachi View Post
yes, adding a sleep in the script is not yielding desired rusults.
And you still don't say what the desired results ARE. WHERE are you putting the sleep statement? Because if you put it as the second line (just under /bin/sh), then it will sleep there for whatever interval you want. It will NOT go further, so nothing else will happen.
Quote:
myCode opens a file sored on a computer, reads whats in that file and sends to the serial port. when i put myCode script on start up, it gives an error "File not found" which means the code was executed on startup before it could get access to all the files stored on the comuputer. So, basically i am looking for a way to delay script and run it when all the files are accessible.......After start up...

its not working...
Again, just saying "its not working" tells us nothing. Where did you put the script? What directory? Name? ANY details?
 
Old 05-31-2013, 09:24 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,748

Rep: Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927
I agree with TB0ne that you have not sufficiently explained what you are trying to accomplish nor how myCode works. It would be easiest to run your script last in the run level i.e. S99myCode as explained above or add it to rc.local depending on what linux distribution your running. Running last would ensure that basically the computer is up and all desired processes are running.
 
Old 06-01-2013, 06:08 PM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
There are various ways to delay, you can query system up time in your script, for example.

The question really is what do you need to delay for? Is there something which you know needs to be established or resolved prior to running your program?

If so, then tie the launch of your program to that prerequisite. Otherwise you'll do ten different delay mechanisms, or add unnecessary delay to make it very long, when what you're really doing is side stepping the problem. If there currently is no signal or information available to indicate that it's "OK" to go, then see if you can figure out a way to create a signal.
 
Old 06-02-2013, 12:04 PM   #9
DaRkBoDoM
Member
 
Registered: Oct 2007
Location: Italy
Distribution: Ubuntu
Posts: 84

Rep: Reputation: 17
If you want to run your script AFTER the startup is complete, consider running it as a cronjob, using the @reboot condition, or at the end of rc.local.

In your script, you should include a loop that checks if file exists, and sleeps until the file is found, anyway.
 
  


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
boot script? tzonga1 Fedora 1 11-13-2004 04:36 PM
boot script freaker2k5 Mandriva 3 08-29-2004 02:44 PM
Boot Script justaguynsrq Linux - Newbie 5 03-18-2004 11:05 AM
Stop boot script at boot time!! kmiles2 Linux - Newbie 1 02-23-2004 10:04 PM
Boot Script jhayes Linux - Software 16 07-18-2003 09:47 AM

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

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