Here's the busy part of the code. I've left out the preliminay setup and the final smbclient copy commands.
cd RAR
echo "Getting RAR files from North Server"
wget -q ftp://username:password@xxx.xxx.xxx.xxx/*.rar;type=i
echo "Getting RAR files from South Server"
wget -q ftp://username:password@xxx.xxx.xxx.xxx/*.rar;type=i
echo "Unpacking RAR files"
unrar -o+ -inul e *raw
echo "Removing .rar files"
rm *.rar
echo "Renaming files and moving them to directories by type"
for src in *;
do
type=$(echo $src | sed -e "s/^.*_//" | sed -e "s/.report//")
tgt=$(echo $src | sed -e "s/\(^.*\)\.\(.*_.*\)/\2/")
echo "Moving $src to ../$type/$tgt"
mv $src ../$type/$tgt
done
cd ../CRS
echo "Processing CRS files"
for src in *.report;
do
# Set some variables
type=$(echo $src | sed -e "s/^........//" | sed -e "s/\(^...\).*/\
+1/")
dest=$(echo $src | sed -e "s/report/csv/")
tid=$(echo $src | sed -e "s/_.*$//")
echo "Src= $src"
echo "Type=$type"
echo "Dest=$dest"
echo "TID= $tid"
echo ""
# Check to see if this is a Flashwave
if [ $type = "FOS" ] \
|| [ $type = "FOT" ] \
|| [ $type = "FOU" ] ;
then
# If it is a Flashwave...
echo "This is a flashwave"
cat $src |
sed -e "/FILL,0,$/d" > /tmp/sedtemp
else
# If this is NOT a Flashwave...
echo "This is NOT a flashwave"
cat $src |
sed -e "/FILL,0,$/d" |
sed -n "/,[1-2][,-].*,$/ {
h
N
s/^.*,\(.*\),$/\1/
H
x
s/\n//g
p
}
/,[0-9]\{1,2\}.*,$/ p" > /tmp/sedtemp
fi
# Find each Port ID section and duplicate it using , instead of -
cat /tmp/sedtemp |
uniq |
# Special case - no dash in Port ID, just a single number
#sed -e 's/\(,[0-9]\{1,2\}\)$/\1,,,,,/' |
# Cleanup caused by special case
#sed -e 's/,,,,,\([0-9]\{1,2\}\)$/,,,,\1,,,,,/' |
# Special case - no dash in Port ID, just a single number
sed -e 's/\(,[0-9]\{1,2\}\),$/\1,,,,,/' |
# Main Port ID reformat
sed -e 's/,\([0-9]\{0,2\}\)-\([0-9]\{0,2\}\)-\{,1\}\([0-9]\{0,2\}\
+)-\{,1\}\([0-9]\{0,2\}\)-\{,1\}\([0-9]\{0,2\}\)/,\1-\2-\3-\4-\
5-,\1,\2,\3,\4,\5/g' |
# Delete mulitple dashes
sed -e 's/--/-/g' |
# Do it again just to make sure
sed -e 's/--/-/g' |
# Delete trailing dashes
sed -e 's/-,/,/g' > $dest
# Update the tidlist
echo "Updating tidlist"
echo $tid >> ../tidlist.txt
echo ""
done
|