Last active
May 6, 2024 16:37
-
-
Save ledangtuanbk/33b1f4e749bf4b2d039b210ea828651b to your computer and use it in GitHub Desktop.
Save connected wifi by date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "start `date`" | |
# Get the directory of the currently running script | |
script_dir=$(dirname "$0") | |
# Change the working directory to the directory of the script | |
cd "$script_dir" | |
echo `pwd` | |
results="results.csv" | |
if [[ -f $results ]]; then | |
echo "File exists." | |
else | |
echo "File does not exist." | |
touch $results | |
fi | |
# Now you're in the directory of the running script | |
# Get network name | |
wifiName=$(/usr/sbin/networksetup -getairportnetwork en0) | |
date=$(date +"%Y-%m-%d") | |
wifiName="${wifiName#"${wifiName%%[![:space:]]*}"}" | |
wifiName="${wifiName%"${wifiName##*[![:space:]]}"}" | |
out="$date;$wifiName" | |
#out="2024-04-24, Current Wi-Fi Network: Deputy_VN" | |
echo $out | |
if grep "$out" $results; then | |
echo "Text found in the file." | |
else | |
echo "Text not found in the file." | |
echo $out >> $results | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Configure to run automatically
Because MacOS have some security System Integrity Protection (SIP)
1 save file as ~/run.sh
2 create a crontab by run command
crontab -e
as content below
* * * * * ~/run.sh >> ~/crontab.log 2>&1
Check log at
~/crontab.log