Operating System - Linux
1754014 Members
7501 Online
108811 Solutions
New Discussion юеВ

Re: need help with script

 
SOLVED
Go to solution
Luka Kodric
Advisor

need help with script

Hello.

I need a SH script that will convert all files in a directory from .ps to .pdf and then delete .ps files

The command i use for converting files is ps2pdf14 -r600 file.ps

Thanks for help. 10 points will be assigned!

5 REPLIES 5
skt_skt
Honored Contributor
Solution

Re: need help with script

run the ps2pdf14 in a for loop
manually confirm the counts for .ps and .pdf and make sure they are same
run the rm in a for loop

for i in `cat ps.list`
do
conversion command
rcode=echo $?
if [ rcode=0 ]
then
##rm $i
fi
done.

Script check the return code of conversion.Run the rm later after manual verification; to be in safe side.
Luka Kodric
Advisor

Re: need help with script

Okay Thanks for help
but i have a question

what does this `cat ps.list` do? i mean i don't have any ps.list file. In a directory there is just a bunch of .ps files.
Dennis Handly
Acclaimed Contributor

Re: need help with script

>what does this `cat ps.list` do?

I was going to suggest that cat shouldn't be used but it seems that Santhosh left out a step of ls *.ps? Besides fixing it, we can improve it:
for i in $(ls *.ps); do
Sandman!
Honored Contributor

Re: need help with script

The 'cat ps.lst' assumes that all .ps file names are stored within a file named ps.lst. Alternatively you could use the script below to do the .ps to .pdf conversion followed by removal of .ps files:

#!/usr/bin/sh

ls -1 /*.ps | while read file
do
ps2pdf14 -r600 $file && rm $file
done
Luka Kodric
Advisor

Re: need help with script

I'd like to thank all of you for your help. :)