Crontab Not Working in MacOS Sierra

Having used Linux and Unix since 1995, I find myself pretty much locked at the hip with crontab to keep my jobs working on a given schedule.  Go figure, as soon as I update my MacOS machine to Sierra and at the same time want to get Clam antivirus configured to auto-scan, I find out it’s not working in there.  It was a bit of a rabbit hole situation, where one thing lead to another.  In the end, I found out that cron has been deprecated in OS X/MacOS, and now Launchd is default and supported.  One of those things that rubs me the wrong way, but it is what it is since it’s not designed to be a server or a Unix system really.

I found /usr/lib/cron to be symlinked to /var/at, and /var/at has a cron.allow file (/var/at/cron.allow).  ‘At’ is also disabled by default.  ‘Atrun’ controls it.  I vi’ed /System/Library/LaunchDaemon/com.apple.atrun.plist and found out that cron was deprecated.

Here’s the skinny on Launchd.  plist files handle the applications that will run within it.  It’s an XML based file which tags a string name for it, the program application that will run, arguments, when it will run, and how frquently.  A description and logs are designated in there as well.  Once one is seen, it’s relatively simple to edit and create your own for any script or application you’d like to run.  That’s what I did.

/Library/LaunchDaemons – holds plist files for global services running as root
/Library/LaunchAgents – Holds plist files only used while users are logged on. (Run as ‘root’)
$HOME/Library/LaunchAgents – Hold plist files used when users are logged on. (run as the userid)

And on to the commands to control launchd… which kinda reminds me of systemd on newer Linux systems, disturbingly.
  • launchctl list – view currently registered plists
  • launchctl load -w <plist file> – adds and registers plist file, starting it.
  • launchctl unload -w <plist file> – remove and deregister plist file.

So, I wanted to have freshclam (clam antivirus script that updates clamav) run regularly.  I created this plist file (/Library/LaunchDaemons/net.clamav.freshclam.plist):

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”&gt;
<plist version=”1.0″>
<dict>
<key>Label</key>
<string>net.clamav.freshclam.plist</string>
<key>LowPriorityIO</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/freshclam</string>
<string>–quiet</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceDescription</key>
<string>Checks for and downloads updates to the ClamAV virus database.</string>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>60</integer>
</dict>
<key>StandardErrorPath</key>
<string>/tmp/freshclam.err</string>

<key>StandardOutPath</key>
<string>/tmp/freshclam.out</string>
</dict>
</plist>

 

And a script I wrote that uses clam antivirus to scan my directories is run by this plist (/Library/LaunchDaemons/net.clamav.clamscan.plist):

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”&gt;
<plist version=”1.0″>
<dict>
<key>Label</key>
<string>net.clamav.clamscan.plist</string>
<key>LowPriorityIO</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/clamscan.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceDescription</key>
<string>Runs a clamscan on the /Users subdirectories</string>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>60</integer>
</dict>
<key>StandardErrorPath</key>
<string>/tmp/clamscan.err</string>

<key>StandardOutPath</key>
<string>/tmp/clamscan.out</string>
</dict>
</plist>

 

After all is said and done, Launchd runs clam antivirus to scan my /Users subdirectories on a regular basis just in case I have something on here I shouldn’t.

It’d be nicer if there would just be an integrated scheduler with the Apple clam antivirus that would translate the scheduling into something that wouldn’t require learning how to build a Launchd script from the beginning.  I can see why they didn’t since it started on Linux and it’s easier to just toss something like this into crontab:

*/60 * * * * freshclam 2>&1 > /tmp/freshclam.log

Advertisements

US Dollar amount to Bitcoin Dollar amount

I found myself needing to calculate how much Bitcoin I’d get for a certain US dollar amount, and I grew tired of checking websites.  I made a quick and easy bash shell script that takes US dollar amount as parameter, and returns the current bitcoin value per $1 USD along with the amount of Bitcoin the amount of USD given in the parameter would purchase.  The output is as follows:

MBP:~ danlund$ ./scripts/btc_amount.sh 200
Current BTC Value per USD: 3796.03
Answer: 200 will currently buy 0.05268600 BTC

Without any further adieu, here’s the script.  Feel free to edit as you wish, I’m just looking to share it.  This will not unfortunately function without a working internet connection since it pulls current BTC data from Coinbase.

#!/bin/bash
if [[ -z $1 ]]; then
echo “Converts USD amount to BTC amount”
echo “$0 <USD amount to convert to BTC>”
exit 1
fi
DOLLARS=$1
AMOUNT=`curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | sed ‘s/,/\’$’\n/g’ | sed ‘s/{/\’$’\n/g’ | grep amount | sed ‘s/”//g’ | sed ‘s/:/\’$’ /g’ | awk ‘{ print $2 }’`
BTC_PER_DOLLAR=`bc <<< “scale=8;1/${AMOUNT}”`
BTC_QUANTITY=`bc <<< “scale=8;x=${DOLLARS} * ${BTC_PER_DOLLAR}; if(x<1) print 0; x”`
echo “Current BTC Value per USD: ${AMOUNT}”
echo “Answer: ${DOLLARS} will currently buy ${BTC_QUANTITY} BTC”

 

EDIT August 22nd, 2017:
Of course I found myself wantign to convert Bitcoins to US dollars, so I wrote a script (based on the above one) that does that.  I figured I’d share it, even though it’s relatively simple.  It saves a a bit of time for those that want to use this.

NOTE: This was created using bash & utils on MacOS with OpenSSL 0.9.8zh 14 Jan 2016.  I tested this on Ubuntu 5.2.1 and the version of Openssl (OpenSSL 0.9.8g 19 Oct 2007) was an issue.  I tested on CentOS 7 with a different version of Openssl (OpenSSL 1.0.1e-fips 11 Feb 2013) and there were no issues.

#!/bin/bash
if [[ -z $1 ]]; then
echo “Converts BTC amount to USD amount”
echo “$0 <BTC amount to convert to USD>”
exit 1
fi
BTC=$1
BTC_VALUE=`curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | sed ‘s/,/\’$’\n/g’ | sed ‘s/{/\’$’\n/g’ | grep amount | sed ‘s/”//g’ | sed ‘s/:/\’$’ /g’ | awk ‘{ print $2 }’`
BTC_PER_DOLLAR=`bc <<< “scale=8;1 / ${BTC_VALUE}”`

USD_QUANTITY=`bc <<< “scale=2;x=${BTC} / ${BTC_PER_DOLLAR}; if(x<1) print 0; x”`
echo “Current USD Value per BTC: ${BTC_VALUE}”
echo “Answer: ${BTC} will currently return ${USD_QUANTITY} Dollars”

Missing my parents

I know I’m an adult of many years.  I have many things in my life that require my responsibility, and many people require it as well.
Lately, I’ve been a child inside.

I miss my parents, and their love.  I miss the look of my father as I told him about my life.  I miss my mother talking about how she felt about current news.  I miss the only stable thing in my life.  I’ve been trying to stay quiet but it’s honestly very hard: I miss my parents more than anything in this world and I never knew I’d say that in my lifetime.

This is a tribute to you dad, you bastard.  You taught me how to keep my nose to the grindstone, and you taught me it’s okay to laugh and enjoy life as you do that.
Mom, you taught me how to love people that don’t deserve it, along with tolerating without end.

Anyway, I’m sorry this isn’t normal for me but it’s needed.  I miss you Mom & Dad.  I love you.

MacOS / OS X – App that makes an app for your scripts

If you’re anything like I am, you have scripts that call do random things, or call other apps behind the scenes to set environments to do other things, etc etc.  The issue I run into is it doesn’t seem pretty to have aliases in my Applications folder.  You can’t set Icons for aliases, and it just sits there as a plain white Icon.  Not cool, man, not cool.  As I was studying Swift code tonight I ran across a gem I thought I’d share which helps amazingly with this problem!  It’s called Platypus, and it creates an app that will run scripts (bash, csh, tcsh, ksh, zsh, Perl, Python, Ruby, Applescript, Tcl, Expect, PHP, Swift, and others) that you set the name for and environment.  Details below.

Platypus1

It’s fairly straight forward, which is nice.  The app name is free form, and so is the author name.  The script path you can type in yourself or find it with ‘select script…’.  If you’re adventurous, the “new” button can be used to create your script right there.
For me, the great part is the interface dropdown which allows you to pick how the called script will be interfaced with.  I pick ‘none’ so it runs in the background out of view.  I have a few ‘wine’ scripts that I call with this, and allows it to run out of sight and out of mind.  As far as icons, I’ve used jpg and ico files by selecting the gear under the picture and choosing ‘select image file…’.  The ones that are able to be used are not shaded out, which is great.

When you click ‘create app’, it will ask you where you want to save it along with the name of the app.  There are other development related selections underneath that can be chosen which I don’t have any experience with.
Screen Shot 2017-07-19 at 9.22.17 PM

I’ve so far used this to call ‘Microsoft Money 2002’ via Wine, along with calling ‘Notepad++’ via Wine.  It works nicely, for me.  It’s available for free (you can donate if you enjoy it) at http://sveinbjorn.org/platypus.

The dude made an awesome app.

For those interested, he also makes another app called “Sloth” that acts as a visual version of the cli tool ‘lsof’.  Kinda neat, I just started looking at it about 10 minutes ago.  It’s available off of his main page, just remove “platypus” from the URL and you’ll see links. (or just go to http://sveinbjorn.org/sloth)
Kinda neat to immediately see where Google Drive is connecting to, that easily.

Macbook Pro external display only while on battery

I haven’t really done this until now, but I figured I’d share how I worked around my issues.

Since I use my new 2017 Macbook Pro as a desktop & laptop, I don’t want to constantly charge the battery while I have it docked.  The problem is that by default MacOS sleeps when the laptop lid is closed.  This is a problem when you don’t want it open & just want to use an external monitor connected via HDMI (through an HDMI -> USB-C adapter) or USB-C directly.  After searching around for a bit, I found a free utility app that helps with this, named “InsomniaX“.  It doesn’t come in a dmg file, just a heads-up.  It’s packaged in a tar.gz tarball which can be decompressed using archive utility.  That’ll drop it into the same directory as the tarball, and you’ll drop and drop it to your Applications folder.

It’s very spartan and almost invisible unless you’re looking for it.  It sits in the tool bar on top, and looks like a crescent moon.  The drop-down menu appears like this when clicked:
Screen Shot 2017-07-15 at 2.31.29 PM

That pretty much sums it up.  As you can see, I selected “Disable Lid Sleep”, and I am operating primarily on my external monitor as I would when plugged in.  The difference when using the power adapter is there is a selection in the Energy Saver section of System Preferences that reads, “Prevent computer from sleeping automatically when the display is off”.  If desired, InsomniaX also has selections in the Preferences area to disable lid sleep while on AC along with starting the application on login.

Screen Shot 2017-07-15 at 2.43.04 PM

Anyway, it’s a neat little utility and does what it’s supposed to do.  Always nice to share those things when you run across them.  Have a great one!

New Set of Apple Airpods Bluetooth Earpieces

I’ve gone through quite a number of bluetooth earpieces.  The one thing I’ve found though is the quality was always subpar compared to normal wired earpieces, and my guess is due to the amount of power required normally to deliver a decent balanced bass.  The market seemed to have fallen on it’s head, and went the route of creating ear inserts and calling them earbuds.  This doesn’t fly in my world, since my ears hurt after using them along with creating compacted ear wax or even collecting on the earbud itself.  They never quite sounded right since it always seemed like they were intentionally pressed closer to the ear drum.

I decided to splurge and get a set of Apple Airpods since they act as headphones along with microphones.  It did hurt to initially purchase them due to the price being artificially high with Apple not officially selling them at their stores since the stock is severely low.  There was a seller on Amazon, and I ordered through them… for $60 more than MSRP.  After a week or two of use, are they worth it to me?  Yes.

Basically, they feel the same as the stock earpods, without wires attached.  Here is a picture of them with Airpod skins protective wraps along with Spigen brand earhooks covers for use on my motorcycle.  I have to say the Spigen earhooks do a great job of containing the Airpods into my ear while riding.
airpods

And this is what they look like without the earhooks, which is how I use them when not on a moving motorcycle.

 

The reason they have sold themselves to me so heavily after using them is for several reasons.  One is that each earpiece senses when inserted into the ear, and alerts the device it is paired with.  This has been very helpful while listening to music and talking on the phone, since as soon as the earpiece is removed the music application senses the change and pauses as if the headphones were unplugged.  This also is helpful while on speaker – as soon as the bluetooth earpiece is inserted, the phone automatically switches over.  The integration with icloud is awesome, if you use it.  Using icloud, the Airpods can be migrated between iPhone to Macbook Pro to iPad to anything else using icloud.  Once the Airpods are added to one of the devices on icloud, it’s added to icloud and instantly added to everything else while being managed by icloud.  I’ve used this to migrate my Airpods between my iPhone to my Macbook Pro, then back to my iPhone after using them for what I needed.

The ability to switch between earpieces is a nice feature as well, and I use this feature while on long production-related calls now.  Using a single earpiece, Once I notice the battery getting low on power, I pull the other one out of the charging case and put it into my ear.  Then, I put the one I’d been using into the case to charge.  The battery in the case I’ve yet to entirely use through the day, and each earpiece I’ve gotten about 2-3 hours of active use (not standby) from between charge.  I’ve also noticed if used as simply a headset, the battery lasts much longer, usually 4-5 hours.

The container holds the earpieces perfectly, since it’s molded to fit and there is a magnetic holder at the base of the container to pull down and secure them.  This makes holding them in your pocket very stable.  The sticker skin that I have around it is mostly to break up the white color.

Until another business decides to make something that has the same ease of use, quality, and integration, I’d buy this again in spite of it being outrageously priced simply because nothing else offers it that I have seen.

EDIT July 29th 2017
I gotta say, these are my favorite set of bluetooth earpieces I’ve ever owned.  I’ve used them for conference calls, listening to music, listening for notifications while at work, etc.  One of my favorite features is being able to pull them out of my ears on an instant, and the music just pausing.  That’s great at work when someone walks up, and I can pull the earpiece from my ear and talk without fiddling with my phone.  The other thing I love is that I’m able to use them when I ride my motorcycle.  With the Spigen brand earhooks, I’ve been able to ride many times to and from work without the earpieces slipping out of my ears.  Now granted I have a windshield on my cruiser which cuts wind quite a bit, but not completely when at 70+ MPH on the freeway.  Also, the noise cancellation works awesome I’ve found.  You’d think with the microphone (on the bottom of the earpiece stem) being so far from your mouth that it would be a problem, but it does just fine when I’m talking normally to someone and there’s noise around me from others talking in the office.  I’ve used it out of the office too, and I haven’t had anyone have issues with hearing me.  In fact, most don’t think I’m on bluetooth, which in itself means a lot.  When I’ve been on long conference calls, I’ve been using one earpiece, and after 2 or so hours when the charge gets to 30-35% I put the other earpiece in my ear then charge the one I’d been using without any interference with the call.  The earpiece recharge only takes 10 or so minutes, and the charging container lasts for quite a few charges.  I went without charging the container for a week or so, only charging once in its life so far when it reached 40%.

The only complaint I have so far is how oddly my phone won’t connect with the airpods even when they are paired.  I turn off bluetooth and turn it back on, and all is well.  I spoke with an Apple store “Genius” (I hate that term), and she said the same as what I’d been doing.  Not sure why, but it’s a quick fix.

EDIT September 15th 2017
I still absolutely love the quality of the Airpods.  I do think Apple needs to work on the bluetooth pairing detection, however.  One thing I notice quite a bit is how iOS at times detects them immediately and other times I have to manually turn them on in the “settings -> bluetooth” area.  I still notice turning off bluetooth and turning it back on helps at times, so it’s definitely an iOS subsystem quirk that more than likely will be fixed as the audience gets larger.  I thought I lost my main Airpod set because I was in a rush and couldn’t find them in the morning, so I picked up another set at the Apple store. (NOT liking to buy them again, btw).  Ended up finding them at home, so now I have two sets and I’m using one set for my personal phone and the other set for my work phone.  With that being said, I’m using the work cell phone for nearly all work calls now, and it’s amazing during meetings.

New 2017 15-inch Macbook Pro

That time has come.  My old laptop, a 2011 Macbook Pro, has been upgraded and repaired enough times were GPU graphics card power was starting to become an issue with new not-so-advanced games.  After holding back so long, with the recent redesign of the Macbook Pro I figured I’d go for it and I’m glad I did in a way.

After a lot of exploring, I ended up picking up the new 15-inch Macbook Pro with 500mb SSD drive and 16gb ram.  The Intel HD graphics 630 GPU chipset holds up pretty well so far with the games I’ve pushed through it, though admittedly I’m not a heavy gamer and have only really pushed it with “Cities: Skylines”.

The 4x USB-C ports originally were a pain in the butt since I needed to get converters to connect, but I noticed it’s all about mindset when dealing with them.  There’s really no need to convert everything over to USB-C since there are plenty of USB hubs/concentrators for sale that plug into a USB-C port to power 3-4 USB ports.  The beauty I found was being able to put my power and HDMI cable into a concentrator, all into one USB-C port.  Since the plugs can never be inserted wrong, that makes it much nicer as well.

I wouldn’t say it’s been worlds different than my old laptop.  CPU is about the same (2.8 ghz i7 on the old laptop, 2.9 ghz i7 on the new one), both have 16gb ram and SSD drives.  The only real difference is the design being lighter/thinner with a much better monitor and graphics chipset.  Newer hardware is always nice, as well 🙂
The touchbar is kind of neat, but it’s not a big selling point for me.  I do like being able to hold down the fn key to see the F-keys appear on the touchbar, though.

So far, the battery does hold up decently, though it does chew through the charge when using the graphics with games.  Tonight with just web surfing and instant messaging, the battery life is about 8 hours.

There are downsides, however.  The memory is soldered onto the board, and the SSD drive is not upgradable.  That is going to be a major issue in the future, and I’m not looking forward to it.