CSS Body Border Linux Crontab Curl Tutorial

CSS Body Border Linux Crontab Curl Tutorial

CSS Body Border Linux Crontab Curl Tutorial

Today we take yesterday’s CSS Body Border Primer Tutorial and its styling principles (and add a dash of Extended Linux Crontab Curl Tutorial as shown below, plus a little “eye of newt” (not shown below)), but allow for dynamic variations of its use by …

  1. make the internal CSS be external CSS, in a CSS file we’ll call body_border.css … why? … so that we can (and like it says, thanks to this very useful link) place the CSS below into that aforesaid mentioned external CSS file …

    #btop, #bbottom, #bleft, #bright { /* thanks to https://css-tricks.com/body-border/ */
    background: gold; /* #a5ebff; */
    position: fixed;
    }
    #bleft, #bright {
    top: 0; bottom: 0;
    width: 5px; /* 15px; */
    }
    #bleft { left: 0; }
    #bright { right: 0; }
    #btop, #bbottom {
    left: 0; right: 0;
    height: 5px; /* 15px; */
    }
    #btop { top: 0; }
    #bbottom { bottom: 0; }
    </style>
    <!--[if lte IE 6]>
    <style>#btop, #bbottom, #bleft, #bright { display: none; }</style>
    <![endif]-->
    <style>
    @media
    /* Fairly small screens including iphones */
    only screen and (max-width: 500px),
    /* iPads */
    only screen and (min-device-width: 768px) and (max-device-width: 1024px)
    {
    #btop, #bbottom, #bleft, #bright { display: none; }
    }

    … and then WordPress’s “good ‘ol” header.php would have, between its <head> and </head> (replacing the need for the big block of CSS code above, as we left it yesterday) …

    <link rel='stylesheet' type='text/css' href='//www.rjmprogramming.com.au/HTMLCSS/body_border.css' />
  2. write some Linux web server PHP code we’ll call body_border.php that randomizes R, G, B, opacity (and uses the rgba(r,g,b,o) syntax to display the colour), width/height run by Crontab and accessed by Curl to run every two hours

  3. <?php
    // body_border.php
    // RJM Programming - April, 2015
    $cssis = @file_get_contents("body_border.css");
    $cb = explode("background: ", $cssis);
    $afb = explode(";", $cb[1]);
    $subcb = "background: " . $afb[0];
    $cw = explode("width: ", $cssis);
    $afw = explode(";", $cw[1]);
    $subcw = "width: " . $afw[0];
    $subch = "height: " . $afw[0];
    $rmm = 127 * rand(0, 2);
    $bmm = 127 * rand(0, 2);
    $gmm = 127 * rand(0, 2);
    $omm = 0.1 * rand(3, 10);
    $hwmm = rand( 5, 8 ) . "px";
    $newcssis = str_replace($subch, "height: " . $hwmm, str_replace($subcw, "width: " . $hwmm, str_replace($subcb, "background: rgba(" . $rmm . "," . $bmm . "," . $gmm . "," . $omm . ")", $cssis)));
    file_put_contents("body_border.css", $newcssis);
    ?>

    … called as per the (“crontab -l” (relevant) record view of the) Linux Crontab Curl arrangement, whereby it is run every 2 hours (at 11 past) …

    11 */2 * * * curl http://www.rjmprogramming.com.au/HTMLCSS/body_border.php

These are the type of “once a day” or “once every now and then” arrangements you can have with randomized arrangements to add interest to your website. These ideas here are being applied to an Apache/PHP/MySql web server, but other web servers that host ASP.Net, for example, would undoubtedly have arrangements for similar functionality, but it may rely on your hosting being “dedicated” rather than “shared”. However, if you have “shared” hosting, it can be worthwhile to ask your web hoster what is possible … probably always good to ask?! If you are shy there are other ways too … Windows laptops or PCs, for example, can do something whenever their users log on (via whatever is in that user’s “Startup” directory (*.exe and *.com and *.bat (which line below could go into)) (or you can use Task Schedular)) and that something could be, for our case, (for the case of Firefox on Windows)…


"C:\Program Files\Mozilla Firefox\firefox.exe" http://www.rjmprogramming.com.au/HTMLCSS/body_border.php

… to change the border whenever you feel like it, but not using batch processing, exactly.

Hope you get some ideas from our tutorial today.

Did you know?

It’s quite likely you did know, but there is no harm in going over it, that with step 1 above we created an external file of CSS (and you may want to read this webpage as well), and this may set you to wondering whether you can “call” one external CSS file from another … and … as you’ve probably guessed, the answer is “yes”. See below, in bold, how we did this regarding emboss_h1.css (changed as per this link, and you can read more of blog posts in the past about this here) via the use of “import” …



@import "../HTMLCSS/body_border.css";

h1 {
color: #ffffff;
font: 24pt Arial;
text-shadow: 0 1px 0 #ccc, 0 2px 0 #c9c9c9, 0 3px 0 #bbb, 0 4px 0 #b9b9b9, 0 5px 0 #aaa, 0 6px 1px rgba(0, 0, 0, 0.1), 0 0 5px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.3), 0 3px 5px rgba(0, 0, 0, 0.2), 0 5px 10px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.2), 0 20px 20px rgba(0, 0, 0, 0.15);
}

… and we’re doing this, mainly, to allow for flexibility into the future. We feel it is not endangering or interfering in anything else because the (new) CSS relies on those HTML “div” elements to exist, anyway, so there still has to be a conscious act to implement this body border by anybody down the track … but it is like falling off a log to do it … as a lot of code at the www.rjmprogramming.com.au domain already has the “link” HTML element in place pointing at emboss_h1.css …


<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>

… so you just add into your HTML four (or fewer?!) “div” HTML elements called “btop”, “bbottom”, “bleft”, “bright”, and there you go. You still have that added flexibility of having control over the HTML syntax used with these “div” elements. For instance, with WordPress, with our “good ‘ol” header.php we change it as per the bold code below to allow for our Ajax contextual help concept (we last talked about with WordPress Blog Context Help Mode Toggler Primer Tutorial … where wajax.js shows the JavaScript Ajax contextual help file changes relevant to today’s work) …


<div id="bleft"></div>
<div id="bright"></div>
<div id="btop" onmouseover='getBodyBorder();' onmouseout='yehBut();' ontouchstart='getBodyBorder();' ontouchend='yehBut();' title=' ... welcome to the long hover functionality that shows Blog Post regarding Body Border'></div>
<div id="bbottom"></div>


Previous relevant Extended Linux Crontab Curl Tutorial is shown below.

Extended Linux Crontab Curl Tutorial

Extended Linux Crontab Curl Tutorial

Sometimes for a website you only want to do a web server task once or a few times a day, and you, ideally, wouldn’t want to run into the remote possibility that two people could perform the task at precisely the same time. This scenario happens often when using server-side languages like ASP.Net and PHP. If it didn’t matter that two people might do the same thing at once then you could do the job within you web-based PHP, and you may consider using a date and time test in your web-based PHP to do your “once or a few times” task in your PHP. This latter idea has the advantage that file ownership issues will probably not crop up because the web user will be manipulating any media or HTML files you may be dealing with, rather than the administrator user that will probably be overseeing your “once or a few times” cron job that we show you here today, extending the functionality we first created with More on Linux Crontab Curl Tutorial as shown below.

With HTML dropdowns containing long lists you often would want at least a couple of ways to sort that list, so with our extension of functionality today, we add to the descending chronological date (default) search of the tutorial below, with new Tutorial Title alphabetical search sort functionality, and allow the rjmprogramming.com.au domain’s landing page show a separate window with the blog displayed in front of the dropdown containing that blog’s tutorial topics, all of this maintained, on a day to day basis, via a cron job … ie. nothing organizational has changed from the tutorial below.

Here is the downloadable PHP programming source code you could call tutorial_options.php and you will see, if you examine the code that it is very specific to conditions here at this rjmprogramming.com.au domain, so please be aware of that, but maybe its concepts can help you out with something else you are tackling. A list of the specifics you would want to address (should you adapt it for your own purposes) include:

  • MySql hostname
  • MySql username
  • MySql password
  • MySql database
  • MySql tablename (may be the same as here with “wp_posts”)
  • Mentions of http://www.rjmprogramming.com.au/wordpress/ (which is this blog URL)

Here is the way we got from the tutorial logic below to this tutorial’s source code’s logic here.

Hope you get some ideas from our tutorial today. Please note that design-wise, lots of people prefer checkboxes or radio buttons, rather that dropdown options as the means to allow other sort methods for this type of job.


Previous relevant More on Linux Crontab Curl Tutorial is shown below.

More on Linux Crontab Curl Tutorial

More on Linux Crontab Curl Tutorial

Sometimes for a website you only want to do a web server task once or a few times a day, and you, ideally, wouldn’t want to run into the remote possibility that two people could perform the task at precisely the same time. This scenario happens often when using server-side languages like ASP.Net and PHP. If it didn’t matter that two people might do the same thing at once then you could do the job within you web-based PHP, and you may consider using a date and time test in your web-based PHP to do your “once or a few times” task in your PHP. This latter idea has the advantage that file ownership issues will probably not crop up because the web user will be manipulating any media or HTML files you may be dealing with, rather than the administrator user that will probably be overseeing your “once or a few times” cron job that we show you here today.

So the task today is to keep the rjmprogramming.com.au’s landing page “Tutorials” dropdown up to date with the latest blog postings, rather than having to manually attend to this with interactive (HTML code) edits and (s)ftp uploads. You may be wondering why not just write the landing page in PHP, and this is a fair point, but the strategy here at this domain is that the landing page and its “fellow” webpages should be independent of MySql, which, under big loads, can go down, and here we use a watchdog to fix that, should it happen. Previously we had a very similar task you can read about with the Linux Crontab Curl Primer Tutorial below. It is so similar, let’s use curl, PHP and crontab to do this task like with that previous task. So this is command line, and this is batch work, but that worry in other types of batch work where you need to worry about where you are as you do any file management, is handled quite well by the wrapping of the job in curl, which takes as its argument a URL, so, implicitly, the place to work with file management, is handled by curl and the PHP we write (specifically where the code uses dirname(__FILE__)).

Here is the downloadable PHP programming source code you could call tutorial_options.php and you will see, if you examine the code that it is very specific to conditions here at this rjmprogramming.com.au domain, so please be aware of that, but maybe its concepts can help you out with something else you are tackling. A list of the specifics you would want to address (should you adapt it for your own purposes) include:

  • the PHP explode methodology (in the code above) assumes there are two select dropdowns (spelt in lowercase) in the underlying HTML code (for rjmprogramming.com.au’s landing page) we are rewriting, and that it is the second one we update with information gleaned (via SQL query) from the WordPress MySql database the PHP reads (where we piece together a $retval string of the HTML option tags belonging to the tutorials HTML select tag)
  • the MySql database access hostname, username, password, database name, database table name
  • the Linux web server file owner used during the (commented out) chown command you may need to consider to allow the crontab’s user be able to leave the files owned by the website user

PHP commands of interest in today’s tutorial include:

Maybe it is just me, but liking “Onion of the 4th dimension” the kind of thinking I gravitate towards is:

  • supervisory command line arrangements
  • all “replace” type functionality … to get the problem into a shape suitable for the bits down deeper into the “core” of your “onion” … Linux-speak would say “kernel” of your “onion”
  • parameters and arguments … continuing on that theme of slotting something (the user is specifically interested in, data-wise) in dynamically for something that “represents” it in the code … sort of, like an “interpretive” approach (often people like to say “scripting”)

Programmers can think in entirely different ways, and if other methods work then that is great (woh!) but if they do not work for any platform (sometimes you don’t intend to cater for every platform known to humans and mangoes … damn … was doing so well … persongoes), and these ideas may really irk many programmers, but you need to consider styles of work that suit your way of thinking best.

So, to do this task we wrote new PHP code and cloned the crontab code used in the tutorial below but change the minute of the hour the task is run, and what is run, in crontab on the Linux web server for the domain at rjmprogramming.com.au … happy studies!


Previous relevant Linux Crontab Curl Primer Tutorial is shown below.

Linux Crontab Curl Primer Tutorial

Linux Crontab Curl Primer Tutorial

Linux (or Unix) is a command line environment that supports interactive and non-interactive task management. Often non-interactive tasks are known as batch processes, often intended not to rely on any user intervention, unless there is a problem.

Today, in this tutorial (which builds on Linux Background Primer Tutorial), we see the power of combining Curl under the auspices of crontab to run a webpage piece of functionality once a day at a specified time.

Some CMS systems like Drupal use crontab to perform actions on the database at regular intervals.

For Windows systems you might want to look at Windows Task Schedular for similar functionality.

Linux has several approaches to activating a task, some (not mentioning all the ways one process can fork or launch another process) of them being:

  • interactively (from the command line)
  • kick off a process from command line, and place in in the background, without supervision, necessarily, via the suffix &
  • kick off a process without supervision, necessarily, via crontab
  • kick off a process in the background (without supervision, necessarily) via nohup
  • kick off a process from command line, and place it in the background, without supervision, necessarily (and optionally change its state via fg and bg)

The previous Linux Background Primer Tutorial is well worth reading below.

Linux Background Primer Tutorial

Linux Background Primer Tutorial

Linux (or Unix) is a command line environment that supports interactive and non-interactive task management. Often non-interactive tasks are known as batch processes, often intended not to rely on any user intervention, unless there is a problem.

In the pre-GUI days batch processes were very prominent, but they still are today, as far as actually getting things done. It is just that the more glamorous activities pass our notice more, but there are servers out there churning away with batch processes, dreaming of the day when they’ll work out how they can make that cup of coffee for you in the morning. And do we ever offer them even a cup’o’tea … it’s a disgrace, so it is.

Linux has several approaches to activating a task, some (not mentioning all the ways one process can fork or launch another process) of them being:

  • interactively (from the command line)
  • kick off a process from command line, and place in in the background, without supervision, necessarily, via the suffix &
  • kick off a process without supervision, necessarily, via crontab
  • kick off a process in the background (without supervision, necessarily) via nohup
  • kick off a process from command line, and place it in the background, without supervision, necessarily (and optionally change its state via fg and bg)

The last four above are often best performed on a shell script, whether that be a Bash, Korn, Bourne or Cshell script. There are some good general tips for batch process scripts:

  • never assume where you are, rather specify the directory to be in, via “cd”
  • never assume that the environment variables will be exactly the same as for an interactive session
  • be more thorough to log errors and log activity to files to see, later, what happened
  • it is not good to proceed on errors (unless you have set up independent means of checking) because there will be no human to interactively decide that the problem should not stop the job proceeding
  • pretty obviously, don’t expect anybody to answer an interactive entry requirement (but you can simulate lots of interactive input via redirected standard input eg. < [filename])

Take a look at some example Linux background processing at this tutorial. In it you will see some crontab work where the parameters are (as explained here … thanks):

MIN = Minute 0-60

HOUR = Hour [24-hour clock] 0-23

MDAY = Day of Month 1-31

MON = Month 1-12 OR jan,feb,mar,apr …

DOW = Day of Week 0-6 OR sun,mon,tue,wed,thu,fri,sat

COMMAND = Command to be run Any valid command-line

The */6 * * * * /Applications/MAMP/htdocs/pdftoimage.sh of our usage runs /Applications/MAMP/htdocs/pdftoimage.sh every six minutes.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Software, Tutorials and tagged , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *