[SOLVED] Scanning multi-page document automation in Bash
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Okay, I replaced the while loop with what you had in the newest one, and ended up with a .tiff named {a...z}{a...z}.tiff, which caused me some confusion.
Did you put three 3 dots instead of 2 in the loop header?
Location: Western Kentucky. No, farther west. Farther... there you go.
Distribution: Linux Mint 17.2 Cinnamon, Kali Linux, Arch (still debugging USB install...)
Posts: 25
Original Poster
Rep:
I just realized why copy and paste is a beautiful tool. There are two dots between a and z. I'll adjust that and retry tomorrow once I get back to the workstation. Although, reading through another thread, would the following work to increment the file names for up to 260 pages (which I should never need)?
Code:
$x=0
$i=1
for y in {A..Z}
if $x=10
then $x=1
else
echo Scanning page $i
scanimage > $y$x yada yada
$x=(( $x + 1 ))
$i=(( $i + 1 ))
end
done
Sorry for the lack of good formatting and the like, I'm on mobile and this keyboard is anything but programming-friendly.
Its missing a few statements. As stated previously the {A..Z}{A..Z} should generate a sequence as AA,AB,AC..AZ,BA,BC..BZ and so on which is 26*26 or 676 possible names or in your case pages and if it works simpler.
Location: Western Kentucky. No, farther west. Farther... there you go.
Distribution: Linux Mint 17.2 Cinnamon, Kali Linux, Arch (still debugging USB install...)
Posts: 25
Original Poster
Rep:
Solved?
I checked the file, and I made a typo in transcription, it was correct in the file. It's not really important, though, as I replaced it with the whole sequence of letters between AA and ZZ (Thanks, Google!), which worked fine. I checked Kali's Bash version, which echoes as 4.something, and I know that support for {a..z} syntax started with release 3, so I'm not sure why it didn't work. Whatever the case, I tested the workaround on my home scanner and it works beautifully. Thank you so much! I'll wait until it executes successfully on the actual workstation before calling it solved, but I think it will be. Here's the final code.
Code:
#!/bin/bash
echo "Type the name you want for the finished file"
read doc
echo "How many pages are in the file?"
read pgs
x=1
for y in AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU AV AW AX AY AZ BA BB BC BD BE BF BG BH BI BJ BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY BZ CA CB CC CD CE CF CG CH CI CJ CK CL CM CN CO CP CQ CR CS CT CU CV CW CX CY CZ DA DB DC DD DE DF DG DH DI DJ DK DL DM DN DO DP DQ DR DS DT DU DV DW DX DY DZ EA EB EC ED EE EF EG EH EI EJ EK EL EM EN EO EP EQ ER ES ET EU EV EW EX EY EZ FA FB FC FD FE FF FG FH FI FJ FK FL FM FN FO FP FQ FR FS FT FU FV FW FX FY FZ GA GB GC GD GE GF GG GH GI GJ GK GL GM GN GO GP GQ GR GS GT GU GV GW GX GY GZ HA HB HC HD HE HF HG HH HI HJ HK HL HM HN HO HP HQ HR HS HT HU HV HW HX HY HZ IA IB IC ID IE IF IG IH II IJ IK IL IM IN IO IP IQ IR IS IT IU IV IW IX IY IZ JA JB JC JD JE JF JG JH JI JJ JK JL JM JN JO JP JQ JR JS JT JU JV JW JX JY JZ KA KB KC KD KE KF KG KH KI KJ KK KL KM KN KO KP KQ KR KS KT KU KV KW KX KY KZ LA LB LC LD LE LF LG LH LI LJ LK LL LM LN LO LP LQ LR LS LT LU LV LW LX LY LZ MA MB MC MD ME MF MG MH MI MJ MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NB NC ND NE NF NG NH NI NJ NK NL NM NN NO NP NQ NR NS NT NU NV NW NX NY NZ OA OB OC OD OE OF OG OH OI OJ OK OL OM ON OO OP OQ OR OS OT OU OV OW OX OY OZ PA PB PC PD PE PF PG PH PI PJ PK PL PM PN PO PP PQ PR PS PT PU PV PW PX PY PZ QA QB QC QD QE QF QG QH QI QJ QK QL QM QN QO QP QQ QR QS QT QU QV QW QX QY QZ RA RB RC RD RE RF RG RH RI RJ RK RL RM RN RO RP RQ RR RS RT RU RV RW RX RY RZ SA SB SC SD SE SF SG SH SI SJ SK SL SM SN SO SP SQ SR SS ST SU SV SW SX SY SZ TA TB TC TD TE TF TG TH TI TJ TK TL TM TN TO TP TQ TR TS TT TU TV TW TX TY TZ UA UB UC UD UE UF UG UH UI UJ UK UL UM UN UO UP UQ UR US UT UU UV UW UX UY UZ VA VB VC VD VE VF VG VH VI VJ VK VL VM VN VO VP VQ VR VS VT VU VV VW VX VY VZ WA WB WC WD WE WF WG WH WI WJ WK WL WM WN WO WP WQ WR WS WT WU WV WW WX WY WZ XA XB XC XD XE XF XG XH XI XJ XK XL XM XN XO XP XQ XR XS XT XU XV XW XX XY XZ YA YB YC YD YE YF YG YH YI YJ YK YL YM YN YO YP YQ YR YS YT YU YV YW YX YY YZ ZA ZB ZC ZD ZE ZF ZG ZH ZI ZJ ZK ZL ZM ZN ZO ZP ZQ ZR ZS ZT ZU ZV ZW ZX ZY ZZ
do
echo "Press enter key to scan page $x"
read answer
echo Scanning $doc-$x
scanimage > $y.tiff --format=tiff --mode=Gray --resolution 200dpi
x=$(( $x + 1 ))
if [ $x -gt $pgs ]
then
break
fi
done
echo "Converting now"
convert *.tiff 1.pdf
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -sOutputFile=$doc.pdf 1.pdf
rm *.tiff 1.pdf
I even understand all of it except the fi. Again, thank you very much for your help; you've been an absolute blessing.
-Kytsuine
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.