How to run a script at a certain time on Linux?
Look at the following:
echo "ls -l" | at 07:00
This code line executes "ls -l" at a specific time. This is an example of executing something (a command in my example) at a specific time. "at" is the command you were really looking for. You can read the specifications here:
http://manpages.ubuntu.com/manpages/precise/en/man1/at.1posix.html
http://manpages.ubuntu.com/manpages/xenial/man1/at.1posix.html
Hope it helps!
Run a command at a specific time
You could try this:
at 1843 <<_EOF_
php /run/this/script.php
_EOF_
edit if what you want to do is run Firefox, try this:
at 1843 <<_EOF_
DISPLAY=:0.0 /usr/bin/firefox
_EOF_
Execute a shell script everyday at specific time
You want to edit your crontab file using
crontab -e
Then you want to add
55 23 * * * COMMAND TO BE EXECUTED
for more info look at this
How I can execute a command at a specific date and time in laravel 5.8?
In accordance to documentation you can use cron to check the:
- month
- day
- hour
- minute
Of execution upon a console command. Though it may cause to run every month date hour and minute you specify on cron but you can call a closure as seen in this piece of documentation. Therefore you can use a closure you the year check at Kernel.php
.
use Carbon\Carbon;
use Illuminate\Support\Facades\Artisan
class Kernel extends ConsoleKernel
{
// Some code exists here
protected function schedule(Schedule $schedule): void
{
// Rest of schedules
$schedule->call(function () {
$year = Carbon::now()->y;
if($year == 2021){
Artisan::call('nuke:country "Kim Young Un" Amerika');
}
})->cron('13 00 12 06 *');
// More schedules
}
// Rest of code here
}
Therefore use a closure to check for the year and then if year is the appropriate one then call the code whilst on cron expression you check for month, day, hour and minute of execution.
An alternative approach is to let the closure handle it all:
$schedule->call(function () {
$dates=[
'2021-06-12 13:00' => [
'commander'=>'Kim Young Un',
'country' => 'America'
],
'2021-06-15 18:00' => [
'commander'=>'Osama Bin Laden\'s clone',
'country' => 'America'
],
'2021-06-15 06:00' => [
'commander'=>'Adolf Hitler\'s clone',
'country' => 'Israel'
],
];
$date = Carbon::now()->format('Y-m-d H:i:s');
if(isset($dates[$date])){
$params=$dates[$date];
Artisan::call("nuke:country \"{$params['commander']}\" {$params['country']}");
}
})->cron('*****');
In other words, execute the command on appropriate dates and continuously check execution date is appropriate.
Related Topics
Scp Command Syntax for Copying a Folder from Local MAChine to a Remote Server
How to Write Non-Ascii Characters Using Echo
"Git Add" Returning "Fatal: Outside Repository" Error
How to Add a Custom Footer to Sphinx Documentation? (Restructuredtext)
Linux Command to Check New Files in File System
When to Use --Dynamic Option in Nm
On Linux - Set Maximum Open Files to Unlimited. Possible
How to Use Linux Command Sort to Sort the Text File According to 4Th Column, Numeric Order
Shared Libraries: Windows VS Linux Method
Why Does Perf Stat Show "Stalled-Cycles-Backend" as <Not Supported>
How to Create a Waveform Image of an Mp3 in Linux
Run a Command at a Specific Time
Wkhtmltopdf Installation Error on Ubuntu
Tcp: When Is Epollhup Generated
Does Epoll(), Do Its Job in O(1)
"Docker Images" Shows Image, "Docker Rmi" Says "No Such Image" or "Reference Does Not Exist"
How to Compare Two Tarball's Content
How to Use "Py" Instead of "Python" at the Command Line in Linux