PSsplitter.sh script

#!/bin/bash

# author Leo Maxwell, August 2011

#pssplitter- quick and dirty script to generate single pages from a multi-page postscript file,

#print them, and delete them. Used with SalsaFax to send multiple faxes from a crystal report backend.

 

#take stdin (captured by piper2 script) and save it as a single postscript file

 

cat – >/tmp/tmpfile.ps

 

#Count pages in postscript file

 

wait && a=$(grep -c %%Page: /tmp/tmpfile.ps)

 

#split file into single pages

 

wait && for((i=1; i<=a; ++i ))

do psselect -p$i /tmp/tmpfile.ps /tmp/tmpfile$i.ps

done

 

#print it to SalsaFax

wait && for((i=1; i<=a; ++i ))

do lp -d SalsaFax /tmp/tmpfile$i.ps

done

 

#delete temporary files

wait && for((i=1; i<=a; ++i ))

do rm /tmp/tmpfile$i.ps

done

 

#delete main temporary file

wait && rm /tmp/tmpfile.ps

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s