Wednesday, 30 September 2015 17:29

Bash Script to update Predict Satellite Tracking TLE Files

Written by 
Rate this item
(0 votes)

Linux BASH shell Script to automatically update TLE files for Predict Software

An automated way for keeping the TLE files up to date

I'm setting up a way for a script to have predict email me the passes of specific satellites, and needed to automate the updating of the TLE files.

I installed predict satellite tracking software onto a raspberry pi that lives on my network.  I'm using this along with other scripts to email me satellite passes on a weekly basis.  This is just a simple way to keep all of the TLE files up to date for the predict satellite tracking software.

 

Copy & Paste the script using a text editor

nano predict_tle-update.sh

Edit the TLE files you wish to download (separated by a comma as shown in the script examples).  Goto http://www.celestrak.com/NORAD/elements/ for a list of TLE files available.

 

To send it to your raspberry pi from another pc using the linux command line scp (directory on pi must already exist)

scp <path-and-file-to-send> pi@<ip-address-of-your-pi:<location-to-store-the-script>

example:
scp  ~/pi_scripts/predict_tle-update.sh This email address is being protected from spambots. You need JavaScript enabled to view it.:~/predict/scripts/

 

Make the script executable

chmod a+rx predict_tle-update.sh

 

To manually run the script on the pi (from the example location)

~/predict/scripts/./predict_tle-update.sh

 

To load a specific TLE file when running predict

predict -t <path-to-file><file-name>

example:
predict -t ~/predict/tle/amateur.txt

 

Run the script automatically everyday at 3am

crontab -e

then add this line to the end of the file

0 3 * * * ~/predict/scripts/./predict_tle-update.sh

hit ctrl-x and select Y when done editing

 

Here's the script

#!/bin/bash
############################################################################
#
# Download TLE files and update predict software
#
# In order to load these files when running predict
# predeict -t <path-to-file><file-name>
# ie: predict -t ~/predict/tle/amateur.txt
#
############################################################################
# Edit the url to download the TLE files
TLEURL="www.celestrak.com/NORAD/elements/"

# Add each file name you wish to download, separated with a comma ie: amateur.txt,weather.txt,visual.txt
TLEFILES="amateur.txt,weather.txt"

# Edit the path to save the TLE files
TLEDIR="$HOME/predict/tle/"

############################################################################
# DO not edit below this line
############################################################################
OIFS=$IFS
IFS="',' || ' '"

if [ ! -d "$TLEDIR" ]; then
 mkdir -p "$TLEDIR"
fi

for index in ${TLEFILES}
    do
    wget -qr "$TLEURL""$index" -O "$TLEDIR""$index"
    command -v "predict -u '$TLEDIR$index'"
done
printf '%s' "$(date)" > /tmp/predict-updated
printf '\n' >> /tmp/predict-updated

IFS=$OIFS

 

Read 3475 times Last modified on Thursday, 08 October 2015 13:00
Algis Salys

Creator and owner of algissalys.com.  Linux enthusiast, electronics tinkerer, and likes to spend time in the workshop building and creating new projects.