Execute command on time Shell Script
Hello, I want to say I am a complete newbie but I want a shell script that will execute a command on a specific time for example on 6:45 am
How is this done, a full example would be very useful! Thank you! |
On Linux systems a service called cron is launching whatever you want at any time you want. It is pre-installed on all Linux systems, no need to write a script for that.
http://unixgeeks.org/security/newbie/unix/cron-1.html Alternatively you can use the at command, for more info look at Code:
man at |
Assuming you want to do this once: Use the at command.
Something like this: Code:
at 06:45 < name_of_script |
Command at(1) is your friend:
Code:
$ echo './myscript.sh' | at 18:45 |
Quote:
|
ok I made this script but nothing happens...
at 17:43 < /home/martin/Desktop/lunchchrome.sh lunchchrome.sh contains #!/bin/sh exec google-chrome |
Quote:
Try changing your script to the following: Code:
#!/bin/sh Also make sure that your script is executable: Code:
$ chmod 755 /home/martin/Desktop/lunchchrome.sh |
Try:
at -f /home/martin/Desktop/lunchchrome.sh 17:45 Also, you can use the atq command to make sure that the command has been queued properly. Some systems don't have at installed any more my default (e.g. my Arch Linux machine). There are various ways to get cron to execute a command once at a particular time. If you want to repeatedly execute a command at a set interval, cron is the way to go. edit: As druuna mentioned, you also need to make sure that you have a proper DISPLAY to launch X based apps. Note that you'll only be able to launch apps as the user running the X server on the local machine, unless you use xhost to modify permissions. |
Oh that worked! Thank you so much!
|
Nice to read you got this fixed and you're welcome!
BTW: Can you put up the [SOLVED] tag. - above the first post -> Please Mark this thread as solved if you feel a solution has been provided. - -or- - - first post -> Thread Tools -> Mark this thread as solved |
All times are GMT -5. The time now is 07:46 PM. |