What are we doing here?

This blog includes a series of videos and references to help new users or enthusiasts better understand how to use open source and free technology tools. The quick links includes more information for accessing many of the tools covered along with other references to learn more for taking advantage of these tools.

Click HERE to see the full list of topics covered!
Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts

More BASH - Auto Sorting Files

BASH SMASH REHASH

I'm sharing a recent script I wrote that might be helpful. 

I had a picture folder on my NAS that was just simply way too large for use on a relatively slow Wifi connection. Essentially hundreds of picture and video files from our family photos.

What would happen on our computers is that when you want to open one file it takes forever as the file viewer tries to cache all the images in the folder to make flipping through them faster. That's a nice feature, but not when the folder / directory is dozens to hundreds of gigabytes in size. 

This script essentially prompts for which folder to sort (must be absolute), then prompts for how many files the user wants to sort per folder. The example below prompts to sort a directory with around 200 files into directories of 20 files apiece. 


Link to the code: autosort.sh

I included a lot of comments so hopefully the script makes sense. Again just a useful tool and might be helpful for those interested in shell scripting. 

BASH! (Bourne Again SHell)

 

BASH and the Linux terminal are essential tools in Linux, and can also be be a very powerful programming language. As shown, it allows for a user to run through the operating system, create, edit, delete files and directories, and have full control over permissions. 

In regards to scripting, probably the most powerful thing about using BASH is the ability to interact and leverage existing Linux commands to grab appropriate input and output. The timeconverter.sh script demonstrates this capability by calling the default 'date' command and using it to get a point of reference of where the user is (or rather where the system is set to), and then using that to help calculate other times around the globe.

What I like about this script - some self pride showing through, sorry - is it's very fast to run and execute. So if one needs to schedule a meeting for 4 pm their local time and wants to see what that time would be in other parts of the world you can run through a slew of possible times in no time at all! 

A few corrections:
Please excuse some typos and little goofs in the video, like having the extra '/' at the end of #!/bin/bash, and finding the /usr/bin/ directory. Hopefully showing the fixes were equally helpful :). The script also doesn't necessarily need the .sh at the end. That is just a habit since many shell scripts have that, but one could simply name the file timeconverter or magictimes or whatever. I should add it is more common for users to add scripts to /usr/local/bin rather than /usr/bin, though as shown either works. 

Tip: cat /etc/environment to see where the PATH links to. PATH in Unix/BSD/Linux defines where all the commands a user can use are located so that they can be run without having to know where each command file is located.

If anyone notices any bugs - the trickiest part is the daylight savings / standard time section - just please leave a comment and I can update.

------------------------------------------

timeconverter:

Source code of the script

--------------------------------------------

Additional reference:

BASH shell

Linux Permissions

The Linux Command Line

Intro for Google Forms and Scripts




This is an introduction and walk through of using Google Forms, reacting to data as it comes in, and also setting a custom script to forward the contents of the request to a specific mail address. This is a feature that is very useful for doing things like surveys and basic initial user/customer engagement.

For internal use it should be more than fine. When embedding in a website there are issues about user privacy which need to be considered and managed. As of this writing, though Google itself does comply with the laws of the land (GDPR in the EU, FCC & FTC in the US, and other regulations in other countries), things like right to be forgotten should be practiced - i.e. a company should be able to either script or manually delete a user entry from someone who requests to do so.

Here are some more references I found helpful when setting up this script.

I am not a privacy lawyer, but I want to make the information available about how useful the forms tool is and can be. The alternative to using something like forms requires a larger amount of code, the ability to setup a database of some sort, employing proper SSL certificates on the server, the server itself and likely storage of said server, another server or software set to send and receive emails, and a manager to run all of that infrastructure and backend. For anything which might not warrant all of that overhead, Google Forms is a great tool for collecting, managing and reacting to feedback.