Bash Scripting
My bash scripting files which I use in my daily work to get some automation and make my life easier. To use the script in your computer simply download the files or clone it, then move the script to folder at your PATH like ”usr/bin” or ”usr/local/bin” The use the command to add the executable flag to it
chmod +x filename # make the script executable
cp filename /usr/local/bin/ # Copy the file to the directory (mac)
#or
cp filename /usr/bin/ # Copy the file to the directory (other)
Now to run the script from anywhere just type the script name and it will run
getGaugesData
This bash script was made to get the header data from DH memory gagues txr files and use awk to calculate the max temperature and pressure and print the results to standard output, also take some values and specific order and add it to a txt file in a csv manner so its easy to convert it to excel later one. Used this script to loop over 70 gauges txt files and extract the values and produce a csv file and another file with the standard output so we can check it one by one along with the file name. Used the below command to do the looping in the terminal after putting all the required files in a folder and running the command
# Make sure you are inside the folder where the txt files are in
for file in *.txt; do getGaugesData $file ;done
getPrices
This script is used to use cURL and go to gold prices site and crude oil prices and scrap the web page and filter for the needed prices of the day. After making the script executable and moved to usr/bin or usr/local/bib then you can simply run the command in terminal like below.
getPrices
A questions will be asked and needs to be answered:
Which price you are looking to read?
- Oil Price type 1
- Gold Price type 2
- Both (leave blank and hit enter)
yttrim
This script is used to download youtube video with a selected duration and start so instead of downloading the whole 1 or 2 hour video instead I can ask the script to download the video starting on time hh:mm:ss and for duration of X sec and the file downloaded will be the small portion you need. The script will be asking for the input as you go so there is no need to pass any arguments to the script. After making the script executable and moved to usr/bin or usr/local/bib then you can simply run the command in terminal like below.
yttrim
Three questions will be asked and needs to be answered:
- Provide the link of the youtube video
- Provide the starting point like (00:01:20) starting first minute and 20 sec (If left blank then it will start from the beginning)
- Provide the duration (should be more than 1 sec)
fzfID
This script is used to fzf quickly search the company assets and crew ID’s very fast using the fzf option. I added the case to select between either 1) Asset or 2) Crew then the fzf will be available to fuzzy search quickly.
fzfID
A questions will be asked and needs to be answered:
What is the type of search you are looking for:
- Asset
- Crew
- PO
- Revenue values
- JobID
*) Nothing
Shrink pdf script
A very useful script found on the internet which helps reduce the pdf file size from the terminal using bash scripting.
Run the chmod +x on the file and add the script in your PATH
chmod +x shrikpdf
cp shrikpdf /usr/local/bin/
- Example of usage ( the number at the end will play a role of the quality and the size )
shrikpdf ~/Downloads/filename.pdf ~/Desktop/shriked_120dpi.pdf 120 shrikpdf ~/Downloads/filename.pdf ~/Desktop/shriked_300pdi.pdf 300
- Case one (120) will create a pdf with resolution of 120 and case two of 300 will be better resolution, you can change the number to match your needs.
See the License comments inside the script file
Killing mouse PID (logitch) - kill_mouse
Using Logitch mouse and key board there come some times that I need to restart the process (kill it) from the activities monitor in my mac so the mouse can act correctly, and for that I made this script to find the PID number and kill it and print the new PID process to ensure that the script has successfully executed
In the script I made the name of the process in a separate variable so any one can use the same script but need to change the mouse process name first
# Find the name of the process and change the name in the below variable to meet your needs
mousePID="logiMgrDaemon --l"
The main script for finding the PID is ps then grep the name of the process and using the -v for grep to remove any other instance of the grep process having the same search term then awk the PID column
ps aux | grep -i "logiMgrDaemon --l" | grep -v rg | grep -v grep | awk '{print $2}'
Download book pages from web site
Bash script used to download the pages from web site based on the number of pages (start to end) and put them in the current folder. Take care before using to ensure the link format so it can work properly.