My first cron job

9. February 2019

The first thing I did was, I added a check in the header.php:

if ( isset($_GET['mycronjob'])) {
	$date = date('Y-m-d H:i:s');
	file_put_contents("test.txt", $date );

	myFunction(); 
}

The first two lines inside of the if statement outputs a test.txt into the same folder as header.php with the time and date. (so I can check that the cron job is doing something)

After that it runs myFunction.

To make this code to run, you have to enter this address in your browser: https://www.example.com/?mycronjob, and that will trigger the content inside of the if statement.

So after that i logged into the server as a user and run this command:

crontab -e

And then I added the following to the file and saved it:

0 * * * * curl --request GET 'https://www.example.com/?mycronjob' >/dev/null 2>&1

This means that it will ‘visit’ this site ones every hour (at 1200, 1300, 1400 and so on). The last part (/dev/null 2>&1) means that it wouldn’t send out any mail to the server admin.

Here are some ‘nice to know’ command you can use instead of ‘0 * * * *’:

Special stringMeaning
@rebootRun once, at startup.
@yearlyRun once a year, “0 0 1 1 *”.
@annually(same as @yearly)
@monthlyRun once a month, “0 0 1 * *”.
@weeklyRun once a week, “0 0 * * 0”.
@dailyRun once a day, “0 0 * * *”.
@midnight(same as @daily)
@hourlyRun once an hour, “0 * * * *”.
Zip a folder in Terminal

24. April 2018

Make sure you stand in your parent directory.

TAR.GZ:

tar -zcvf archive-name.tar.gz directory-name

ZIP (not always the server has zip library. Use Tar.gz):

zip -r filenameforthezipedfile thefolderwhoisgoingtobezipped
Terminal command nice to know

20. April 2018

mkdir (create new folder)
rmdir (delete folder)
rm -rf folder (delete folder with content)
rm -r (delete file)
touch index.html (create document)
open index.html (open document)
open -a "Visual Studio Code" index.html (open file in specific app)
cd .. (go back)
ls (list)
ls -las (better list)
la -las (also better list)
pwd (present directory)
open . (open folder in Finder)
mv oldname.jpg newname.jpg (change name on file or folder)
man xxxx (shows a manual of a command)
Command + K (clean the terminal)
Command + Z (gets back)

chmod 700 filename - Sometimes you have to be superuser (SU) - Set all Rights
grep -r wc_checkout_params (Search for something)
find . -type f -exec chmod 644 {} \; - give rights
find . -type d -exec chmod 755 {} \; - give rights

du -sh */ (check the folder size, one level)
du . -h --max-depth=1 (check the folder size)
df (show server size)


Remove everything on the computer in terminal:
sudo rm -rf /
Logging of the server for some strange reason

20. April 2018

It is not every ISP that supports ‘keepalive’, if you are using a mobile connection for example, vill this happen.

If it happens with Ssh, you can run ‘top’ when you leave the terminal. Or you can: https://unix.stackexchange.com/questions/34004/how-does-tcp-keepalive-work-in-ssh

Make a script in Terminal

20. April 2018

1. Create a file: nano xxxxxxxx
2. Put in your commands that you what to run
3. Save the file (Ctl + O, Return, Ctl + X)
4. Make the file Executable: chmod 0760 xxxxxxxxxx (or chmod 700 xxxxxxxxx)
5. Run the script: ./xxxxxxxxxxxxx