cd /usr/local/nagios/libexec
vi check_4apache
#!/bin/bash
# mikeyom@gmail.com 03-2023
my_status=`systemctl show -p ActiveState apache2 | sed 's/ActiveState=//g'`
if [ $my_status != 'active' ]; then
echo "Critical - Apache2 service is not running"
exit 2
fi
echo "OK - Apache2 is running"
exit 0
define service {
use local-service ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_4apache
notifications_enabled 0
}
Update the packages
apt update -y
apt full-upgrade -y
apt install update-manager-core -y
apt-get --purge autoremove
apt-get clean
reboot
Upgrade Ubuntu 18.04 to 20.04
do-release-upgrade -d
Google Fit User Tracking
Find the average session distance travelled by Google Fit users based on GPS location data. Calculate the distance for two scenarios:
Taking into consideration the curvature of the earth
Taking into consideration the curvature of the earth as a flat surface
Assume one session distance is the distance between the biggest and the smallest step. If the session has only one step id, discard it from the calculation. Assume that session can't span over multiple days.
Output the average session distances calculated in the two scenarios and the difference between them.
Formula to calculate the distance with the curvature of the earth:
user_id: varchar
session_id: int
step_id: int
day: int
latitude: float
longitude: float
altitude: float
Your task is to calculate the average distance based on GPS data using the two approaches. One is taking into consideration the curvature of the Earth, the other is not taking it into consideration.
The question gives you formulas for both approaches. As you can see, this python coding interview question is math-heavy. Not only do you need to understand this level of mathematics, but you also need to know how to translate it into a Python code.
Not that easy, right?
The first thing you should do is recognize there’s a math Python module that gives you access to the mathematical functions. You’ll use this module a lot in this question.
Let's start by importing necessary libraries and sine, cosine, arccosine, and radian functions. The next step is to merge the available DataFrame with itself on the user ID, session ID, and day of the session. Also, add the suffixes to IDs so you can distinguish between them.
import numpy as np
import pandas as pd
from math import cos, sin, acos, radians
df = pd.merge(
google_fit_location,
google_fit_location,
how="left",
on=["user_id", "session_id", "day"],
suffixes=["_1", "_2"],
)
df["step_var"] = df["step_id_2"] - df["step_id_1"]
df = df.loc[
df[df["step_var"] > 0]
.groupby(["user_id", "session_id", "day"])["step_var"]
.idxmax()
]
df["distance_curvature"] = pd.Series()
for i, r in df.iterrows():
df.loc[i, "distance_curvature"] = (
acos(
sin(radians(r["latitude_1"])) * sin(radians(r["latitude_2"]))
+ cos(radians(r["latitude_1"]))
* cos(radians(r["latitude_2"]))
* cos(radians(r["longitude_1"] - r["longitude_2"]))
)
* 6371
)
df["distance_flat"] = pd.Series()
for i, r in df.iterrows():
df.loc[i, "distance_flat"] = (
np.sqrt(
(r["latitude_2"] - r["latitude_1"]) ** 2
+ (r["longitude_2"] - r["longitude_1"]) ** 2
)
* 111
)
result = pd.DataFrame()
result["avg_distance_curvature"] = pd.Series(df["distance_curvature"].mean())
result["avg_distance_flat"] = pd.Series(df["distance_flat"].mean())
result["distance_diff"] = result["avg_distance_curvature"] - result["avg_distance_flat"]
result
Content deleted
#!/bin/bash
# mikeyom@gmail.com 03-3023
my_path=/var/lib/jenkins/mike_scripts/z_labels
gcloud compute instances --project myproject list --format='table(name,status,labels)' | grep -v gke | grep -v perm | grep -v temp | grep RUNNING | awk '{print $1}' > $my_path/nolabel.txt
if [ -s $my_path/nolabel.txt ]; then
echo "shutting down"
mail -s "Shuttting Down MY-Proj No Label" 510@mms.att.net < $my_path/nolabel.txt
while read -u3 shutdown
do
gcloud compute instances stop $(gcloud compute instances list --filter="name:$shutdown" --uri)
done 3< $my_path/nolabel.txt
else
echo "Nothing to shutdown"
fi