Use the Unofficial Bash Strict Mode (Unless You Looove Debugging)

I call this the unofficial bash strict mode. This causes bash to behave in a way that makes many classes of subtle bugs impossible. You’ll spend much less time debugging, and also avoid having unexpected complications in production.

Source: Use the Unofficial Bash Strict Mode (Unless You Looove Debugging) (aaron maxwell)

How To Create A VPN Killswitch Using Iptables on Linux

Use iptables to create a VPN killswitch to protect against data leaks.

…..

If you’re connected to a VPN, you need a killswitch. No, it’s not as metal as it sounds. It’s just a mechanism that stops your Internet connection when you’re disconnected from the VPN. It protects you from inadvertently leaking sensitive information onto the Internet when the VPN connection drops.

Source: How To Create A VPN Killswitch Using Iptables on Linux – LinuxConfig.org

Guide to Sort Files by Date Using LS Commandline in Linux

The ls command is used to list directory contents and the results can be sorted upon several criteria such as by date, alphabetical order of filenames, modification time, access time, version and file size.

In this article, I will show you how to sort files by date using ls command in Linux.

Source: Guide to Sort Files by Date Using LS Commandline in Linux (LinOxide)

23 Advanced Bing Search Tips And Tricks You Should Know

Bing has several search engine shortcuts and advanced features that can be used to get better and accurate search results. These Bing search tips and tricks will help you narrow down search results to find exactly what you are looking for.

Source: 23 Advanced Bing Search Tips And Tricks You Should Know (Fossbytes)

This Siri Shortcut Automatically Triggers Camera Every Time Cops Pull You Over

I knew that day that the Shortcuts app has paved the way for automation in iPhone, but I didn’t realize that it can also be used to keep a track on the proliferating police abuse.

Source: This Siri Shortcut Automatically Triggers Camera Every Time Cops Pull You Over (Fossbytes)

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.

Featured Article:

Recent Posts

Recent Comments

Archives

Categories

Meta

GiottoPress by Enrique Chavez

%d bloggers like this: