Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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
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.
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.
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?
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.