I have been using Windows Subsystem for Linux (WSL) for a while now and sometimes I create a distribution and forget the password. If you find your self in the same situation, just follow these steps:
- Open the Windows Shell.
- Type in
wsl -l to get the list of WSL Distributions you have on your system.
- Login to the distribution using
wsl -d [Distribution Name].
- Type in
whoami to get your default user name. Note this down.
- Logout of the distribution, by typing
- Log in as root:
wsl -d [Distribution Name] -u root.
- Change the password for the user by running this
passwd [User Name] and follow the instructions.
- If all goes well you should get a “passwd: password updated successfully” message.
- Logout again using
- Now you can use the new password for your WSL Distribution default user.
Hope this was helpful to you. Thanks for reading.
The Laravel web framework comes with a lot of powerful tools and one of them it the Task Scheduler. This allows you to create and manage all your automated – Cron Jobs – tasks within the framework. If you do not write Cron jobs often, going through documentation or memorizing the Crontab syntax and expression can be extra work (I usually use crontab.guru to simplify this ). Laravel uses functions such as
everyTwoMinutes() which is simple to remember and implement. There is also per second scheduling which is not available by default on crontab.
First, you have to open the
app/Console/Kernel.php file. Your scheduled task will be added in the
schedule(Schedule $schedule) function, by calling the
$schedule object. There four main types of calls you can make using the
- A closure function containing Laravel/PHP code you wish to run.
- A command which runs an Artisan command.
- A queued Job.
- Command line scripts which can run external scripts.
I will be running an external script (using
exec ) to get my systems stats and then send them to myself every 5 minutes. To use an already setup docker environment you can clone this repo and follow the setup instructions (If you choose to use the docker environment. Run your commands in the ‘web’ container) . Copy the code block below in the schedule function:
$command = 'echo "------------------" >> out.txt &&';
$command .= 'top -b -n 1 >> out.txt &&';
$command .= 'echo "------------------" >> out.txt &&';
$command .= 'cat /proc/meminfo >> out.txt &&';
$command .= 'echo "------------------"';
Then first test using
php artisan schedule:test select the number associated with this task and click enter. if there are no errors, run
php artisan schedule:work to start the scheduler if you are on a development environment. For production, add this to your Crontab :
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
- Ensure email sender (mailer) of choice is configured on the .env file.
- If you choose to use the docker environment. Run your commands in the ‘web’ container.
That’s it, you can include other server stats you want to send through email in the
exec function of the scheduler.
- Laravel Documentation: https://laravel.com/docs/10.x/scheduling#task-output