Created
July 8, 2023 18:54
-
-
Save jumblies/782b52efbd3274496a646416468f6746 to your computer and use it in GitHub Desktop.
20230708 Brother brscan-skey scantofile.sh script with renaming
This file contains hidden or 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
#!/bin/sh | |
# | |
# $1 = scanner device | |
# $2 = friendly name | |
# 100,200,300,400,600 | |
# 200 is a little more than half the size but still readable. | |
resolution=300 | |
device=$1 | |
device='brother4:net1;dev0' | |
#BASE= /home/glamke/brscan | |
sleep 1 | |
# this causes problems with ocrmypdf | |
output_tmp=/home/glamke/brscan/"`date +%Y%m%d_%H%M%S`" | |
output_filename="`date +%Y%m%d_%H%M%S`"_CLR.pdf | |
echo "scan from $2($device)" | |
# This is introduced to kill scanadf if the button on the scanner isn't pressed. | |
# It has a timeout of 5 min before killing scanadf. | |
# testing without this | |
#nohup /opt/brother/scanner/brscan-skey/script/kill_scan_adf.sh > /dev/null 2>&1 & | |
# hangs on single page if putton not pushed. with below. | |
# nohup with tailing & didn't work. so back to kill script. | |
# | |
#scanadf --script-wait --mode '24bit Color[Fast]' --resolution 300 -y 270 -o "$output_tmp"_%04d".pnm" | |
# 20190220 Working very well with timeout command below. | |
timeout 3m scanadf -v --script-wait --mode '24bit Color[Fast]' --resolution 300 -y 270 -o "$output_tmp"_%04d".pnm" | |
for pnmfile in $(ls "$output_tmp"*) | |
do | |
echo pnmtops "$pnmfile" "$pnmfile".ps | |
# pnmtops -imagewidth=8.5 -width=8.5 "$pnmfile" > "$pnmfile".ps | |
pnmtops "$pnmfile" > "$pnmfile".ps | |
rm -f "$pnmfile" | |
done | |
echo psmerge -o"$output_tmp".ps $(ls "$output_tmp"*.ps) | |
psmerge -o"$output_tmp".ps $(ls "$output_tmp"*.ps) | |
echo "Converting ""$output_tmp".ps "$output_tmp"_CLR.pdf | |
ps2pdf "$output_tmp".ps "$output_tmp"_CLR.pdf | |
# Convert same PS to greyscale and then to pdf | |
#gs \ | |
# -sDEVICE=pdfwrite \ | |
# -sProcessColorModel=DeviceGray \ | |
# -sColorConversionStrategy=Gray \ | |
# -dOverrideICC \ | |
# -o "$output_tmp"_GS.pdf \ | |
# -f "$output_tmp"_CLR.pdf | |
# Failed options | |
# ps2pdf "$output_tmp"_GS.ps "$output_tmp"_GS.pdf | |
# ps2pdf -dUseFlateCompression=true does nothing since it is a scanned image | |
# pdfcrop "$output_tmp".pdf "$output_tmp"_crop.pdf #not needed after adjusting adf size above | |
#cleanup | |
for psfile in $(ls "$output_tmp"*.ps) | |
do | |
rm $psfile | |
done | |
rm -f "$pnmfile".ps | |
#OCRmyPDF | |
#docker_ocrmypdf='docker run --rm -i --user "$(id -u):$(id -g)" --workdir /data -v "/home/glamke/brscan:/data:rw" jbarlow83/ocrmypdf' | |
#test with output.pdf file | |
docker run --rm -i --user "$(id -u):$(id -g)" --workdir /data -v "/home/glamke/brscan:/data:rw" jbarlow83/ocrmypdf --deskew /data/"$output_filename" /data/$output_filename | |
# !/bin/bash | |
# file=/home/glamke/brscan/$1 | |
infile=/home/glamke/brscan/"$output_filename" | |
outfile="${infile%_*}_CLR".txt | |
echo 'outfile = '"$outfile" | |
echo 'infile = '"$infile" | |
pdftotext "$infile" | |
grep -i "Veteran" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_VA.pdf | |
# rm $infile | |
fi | |
grep -i "Harris" $outfile | |
if [ $? -eq 0 ]; then | |
echo "Found Harris"; | |
newname="${infile%_*}" | |
mv $infile "$newname"_Teeter.pdf | |
# rm $infile | |
fi | |
# grep -i "111849320610" $outfile #costco member # | |
grep -i "111895513038" $outfile #costco member # | |
if [ $? -eq 0 ]; then | |
echo "Found Costco"; | |
newname="${infile%_*}" | |
mv $infile "$newname"_Costco.pdf | |
# rm $infile | |
fi | |
grep -i "COSTCO" $outfile #costco member # | |
if [ $? -eq 0 ]; then | |
echo "Found Costco"; | |
newname="${infile%_*}" | |
mv $infile "$newname"_Costco.pdf | |
# rm $infile | |
fi | |
grep -i "CITY SERVICES" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_GSOWater.pdf | |
# rm $infile | |
fi | |
grep -i "B&B Food Mart" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_BB_GAS.pdf | |
# rm $infile | |
fi | |
grep -i "1781980778" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_DukeEnergy.pdf | |
# rm $infile | |
fi | |
grep -i "CUSTOM CARE" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_CustomCare.pdf | |
# rm $infile | |
fi | |
grep -i "Massage" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_Massage.pdf | |
# rm $infile | |
fi | |
# grep -i "Dental" $outfile | |
# if [ $? -eq 0 ]; then | |
# newname="${infile%_*}" | |
# mv $infile "$newname"_Dental.pdf | |
# rm $infile | |
# fi | |
grep -i "Optical" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_Optical.pdf | |
# rm $infile | |
fi | |
grep -i "Veteran" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_VA.pdf | |
# rm $infile | |
fi | |
grep -i "Walmart" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_Walmart.pdf | |
# rm $infile | |
fi | |
grep -i "Target" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_Target.pdf | |
# rm $infile | |
fi | |
grep -i "aldi" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_ALDI.pdf | |
# rm $infile | |
fi | |
grep -i "mythos" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_mythos.pdf | |
# rm $infile | |
fi | |
grep -i "turnston" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_HOA.pdf | |
# rm $infile | |
fi | |
grep -i "B&B" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_BnB.pdf | |
fi | |
grep -i "UnitedHealthcare" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_UnitedHealthcare.pdf | |
fi | |
grep -i "Optum" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_OptumRx.pdf | |
fi | |
grep -i "Sheetz" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_Sheetz.pdf | |
fi | |
grep -i "Headway" $outfile | |
if [ $? -eq 0 ]; then | |
newname="${infile%_*}" | |
mv $infile "$newname"_Headway.pdf | |
fi | |
rm $outfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment