Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AossTower
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MetObs
AossTower
Commits
14b1e040
Verified
Commit
14b1e040
authored
7 years ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
Add initial loggernet rotate script for aoss tower
parent
89ee9c50
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/loggernet_rotate.sh
+113
-0
113 additions, 0 deletions
scripts/loggernet_rotate.sh
with
113 additions
and
0 deletions
scripts/loggernet_rotate.sh
0 → 100755
+
113
−
0
View file @
14b1e040
#!/usr/bin/env bash
# Separate continuous loggernet files in to daily files.
# LoggerNet writes data to two growing files. Every day at midnight this script should be run.
alias
errcho
=
'>&2 echo'
LOGGERNET_PATH
=
/opt/CampbellSci/LoggerNet
LOGGERNET_DATA
=
/data/loggernet
#LOGGERNET_DATA=/tmp
HEADER_SIZE
=
0
INPUT_PREFIX
=
"rig_tower"
OUTPUT_PREFIX
=
"rig_tower"
#FILE_SUFFIXES="engdata metdata gpsdata"
FILE_SUFFIXES
=
"_"
INPUT_EXT
=
"dat"
OUTPUT_EXT
=
"ascii"
DAYS
=
6
assert_python
()
{
python
-c
"import sys; sys.exit(sys.version_info[0] >= 3)"
if
[
$?
!=
0
]
;
then
errcho
"'python' must be version 3"
exit
1
fi
}
pause_loggernet
()
{
$LOGGERNET_PATH
/cora_cmd
<<
EOF
connect localhost;
set-lgrnet-setting 1 0;
exit;
EOF
}
unpause_loggernet
()
{
$LOGGERNET_PATH
/cora_cmd
<<
EOF
connect localhost;
set-lgrnet-setting 1 1;
exit;
EOF
}
#yyyymmdd_dates_in_csv() {
# # parse out the unique dates from the LoggerNet timestamped CSV data file
# # Returns epoch seconds
# awk -F"," -v "header_size=$HEADER_SIZE" 'NR>header_size { print $1 }' <&0 | \
# awk -F" " '{ time_spec=sprintf("%04d %02d %02d 00 00 00", substr($1, 2, 4), substr($1, 7, 2), substr($1, 10, 2)); print mktime(time_spec) } ' | \
# sort | \
# uniq
#}
# completes almost every feature of the below for loops
# TODO: if file doesn't exist add the header
# TODO: Handle output file suffix
yyyy_jjj_tower_split
()
{
awk
-F
","
-v
"header_size=
$HEADER_SIZE
"
'NR>header_size { time_spec=sprintf("%04d 01 %03d 00 00 00", $2, $3); print mktime(time_spec) }'
$1
|
\
sort
|
\
uniq
|
\
awk
-v
"file_prefix=
$OUTPUT_PREFIX
"
-v
"file_ext=
$OUTPUT_EXT
"
-v
"input_file=
$1
"
'{ file_date=strftime("%Y-%m-%d", $0); jday=strftime("%j", $0); y=strftime("%Y", $0); output_file=sprintf("%s.%s.%s", file_prefix, file_date, file_ext); command=sprintf("grep \"%d,%d\" %s >> %s", y, jday, input_file, output_file); command | getline val; print output_file }'
;
}
oops
()
{
errcho
$*
exit
1
}
assert_python
if
[
$#
-eq
1
]
;
then
ARCHIVE_PATH
=
$1
else
ARCHIVE_PATH
=
$LOGGERNET_DATA
fi
if
[
!
-d
$ARCHIVE_PATH
]
;
then
errcho
"Archive destination location does not exist:
$ARCHIVE_PATH
"
exit
1
fi
# Pause LoggerNet so it doesn't perform any ingest and doesn't affect the files we'll be working with
pause_loggernet
||
oops
"Could not pause LoggerNet"
cd
$LOGGERNET_DATA
for
file_suffix
in
$FILE_SUFFIXES
;
do
if
[
$file_suffix
==
'_'
]
;
then
# we don't have a suffix
file_suffix
=
""
fi
input_file
=
"
${
INPUT_PREFIX
}${
file_suffix
}
.
${
INPUT_EXT
}
"
if
[
!
-s
$input_file
]
;
then
errcho
"Input file
${
input_file
}
does not exist"
continue
fi
# Create a temporary file with just the header information in it
header_fn
=
"header
${
file_suffix
}
.tmp"
head
-n
${
HEADER_SIZE
}
${
input_file
}
>
$header_fn
# Split main file in to dated files
yyyy_jjj_tower_split
$input_file
# copy the header back to the original file
cp
$header_fn
$input_file
# remove the temporary header file
rm
${
header_fn
}
# Remove the input file if it only has the header left (just in case loggernet wants to make a new header)
done
# Have LoggerNet continue data collection
unpause_loggernet
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment