how can i write a shell script that will run at startup and introduce a delay in the start of an application
Solution 1
You can add a delay time with sleep
command.
man sleep
for more info .
Example
I want to startup a program with delay of 10 seconds. I create an entry in the startup applications with this in command field
sleep 10;/usr/bin/<program name>
Example 2
I want to create a script with the delay (sleep) option and add this script to startup applications
gedit delayscript.sh
and I add these lines
#!/bin/bash
sleep 10
/usr/bin/<program name>
save the script and give it executable permissions
chmod +x delayscript.sh
and add it to startup applications (command field) with full path
/home/username/delayscript.sh
Solution 2
while this is a great answer:
sleep 30; <app-name>
It does have one hidden downside: if you ever want to kill the delayed app before it starts to run, it's not anywhere in ps -ef; instead all you see is "sleep 30". And, if you kill that sleep command, rather than preventing the delayed app from running it just makes the app run immediately. So I suggest this alternate script (delay) which, if killed, prevents the delayed app from running:
#!/bin/bash
# easily killable sleep
sleep $1
shift
$@
example:
delay 10m rebuild-database
now, if you decide for some reason to prevent the database from being rebuilt, you can kill the shell script.
Related videos on Youtube
Nirmik
A true LINUX lover and APPLE fan!! An aspiring OS DEVELOPER i love to work on linux. :) With an encounter with linux from the past 1year,I have definitely succeded in creating a LINUX community around with many friends. Love LINUX for every bit of it..!! :) <3
Updated on September 18, 2022Comments
-
Nirmik almost 2 years
I have an application installed for my samsung NP-RV509 installed that makes the fn keys work properly..
I figured it out that it is the reason behind almost 30sec xtra booting time...
so i was wondering if i could write a shell/python script(actually i myself cant as i dont know shell/python prog) that will introduce a delay may be using a loop or something and then start the above application...I shall add this script in start up apps...
this will simulate the running of that program at startup but, delayed in actual...
so how can i achieve this?(help wth the code)
thankyou! :)
-
Glutanimate over 11 yearsPossible duplicate: askubuntu.com/questions/28685/… ; also you might want to use this instead of sleep, if you are using a DE like Unity or GNOME.
-
-
Havnar almost 9 yearsis this non blocking? (i.e. will this hold up the whole startup process?)
-
NickTux almost 9 yearsNo, it won't hold the whole startup process. It will delay to execute this specific script only.