How to stop a bash script from being executed too frequently

Every so often something really useful appears on Reddit, and this is such a case.  You may encounter a situation where you want to execute the contents of a bash script, but not more frequently than every few seconds.  A Reddit user wanted to know How to check if a command in .bashrc has been executed within last 10 seconds if yes don’t execute the command again. The response by Reddit user mdaffin is brilliant in its simplicity, and can be used in any bash script where you don’t want the contents executed too often:

Write a time stamp to some file, check said file before you run the command if now – timestamp > 10s run the command and update the timestamp.

EDIT: Like this (with modification times instead):

TS_FILE="$HOME/.cache/your-app-lock"
if [[ ! -f "$TS_FILE" ]] || [[ "$(expr "$(date +%s)" - "$(stat -c %Y "$TS_FILE")")" -gt 10 ]]; then
touch "$TS_FILE"
echo "running"
fi

You’d replace the echo "running" line with the part of the bash script you want to run only if it’s been 10 seconds since the last time the script was run, or whatever number of seconds you specify after the -gt. If the bash script actually outputs a file as part of its normal operation then you could specify that file in the TS_FILE= line; there would be no need to create a separate timestamp file (unless some other process could also modify that same file).

This doesn’t actually stop the bash script from running; it just prevents it from executing the part of the script that you don’t want executed too frequently. This could be very useful in a situation where without such protection, the too-frequent execution of the script might cause something undesirable to happen (such as getting locked out of an online site for hammering it with requests). Depending on the situation there may be other, perhaps even better ways to avoid this possibility, but in other cases this may indeed be the best approach.

How to Remove Stuck Time Machine Backups from Mac Trash Due to System Integrity Protection Error

If you’re trying to remove a Time Machine backup from a drive and find that it’s stuck in the Mac Trash with a specific error message stating the trash can’t be emptied because “Some items in the Trash cannot be deleted because of System Integrity Protection”, then read on to learn how to resolve this particular Time Machine backup removal problem.

Source: How to Remove Stuck Time Machine Backups from Mac Trash Due to System Integrity Protection Error

Convert an older model USB printer to a networked printer using a Raspberry Pi or other Linux-based computer — also works well for making an older printer compatible with a newer version of MacOS

We originally set out to do this because we were having problems getting an older model laser printer, specifically a Konica Minolta PP1350W, to work with MacOS High Sierra (10.13). With previous versions of MacOS we’d been able to connect the printer directly to the computer, and with some fiddling with drivers and other software, get it to work. But newer versions of MacOS seem to be far less tolerant of this, and we had a spare Raspberry Pi, so the idea came to us to use the Raspberry Pi as a bridge between the printer and any computers on the local network from which we wanted to be able to print. The bonus is that the printer is no longer tethered to a single machine, but instead can potentially be used by any computer on the local network.

You do not need to have a Raspberry Pi to make this work – any computer that can run Linux will do. And of course the Raspberry Pi or other Linux computer can be used for other purposes besides this. We do not guarantee that this technique will work for every older printer out there, but this will work with a surprising number of them.

Source: Convert an older model USB printer to a networked printer using a Raspberry Pi or other Linux-based computer — also works well for making an older printer compatible with a newer version of MacOS – Two “Sort Of” Tech Guys

MacBuntu 18.04 Transformation Pack Ready for Ubuntu 18.04 Bionic Beaver

MacBuntu (Macbuntu Mojave/High Sierra/El Capitan/Yosemite) transformation pack is ready for Ubuntu 18.04 Bionic Beaver, we were constantly asked for this pack to be available on our site, so here it is for you guys. In this transformation pack we are featuring many themes for almost every desktop, so you don’t have to worry about the desktop you are using whether it is Gnome Shell, Mate, Xfce, Cinnamon or any other desktop. You can simply install it in Ubuntu/Linux Mint or any other Ubuntu based distribution and make your desktop look like Mac OS X. The Unity desktop is still supported in case you are using unofficial version of Unity desktop. In this pack you will find plenty of light variants as well as dark versions, which is managed by different creators and I would like to thank all of them for contributing these themes (McOS-themes, macOS High Sierra, macOS 11, macOS High Sierra – ELBULLAZUL). There are two themes for cursors, for dock we recommend you to install Plank dock and we are providing themes for it as well (credits: KenHarkey and erikdubois. Also we are including themes for Gnome Shell, for Cinnamon, and three icon packs in this transformation pack.

Source: MacBuntu 18.04 Transformation Pack Ready for Ubuntu 18.04 Bionic Beaver – NoobsLab

How to install Kodi media player to Ubuntu 18.04 (Bionic Beaver) Desktop

We recently wanted to install the Kodi media player software to a system running Ubuntu 18.04 desktop.  Here is the procedure we followed.

Source: How to install Kodi media player to Ubuntu 18.04 (Bionic Beaver) Desktop – Two “Sort Of” Tech Guys

Featured Article:

Recent Posts

Recent Comments

Archives

Categories

Meta

GiottoPress by Enrique Chavez

%d bloggers like this: