find eof, then process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find eof, then process
# 8  
Old 12-22-2003
Actually, I never realized that PDF's have that string at the end either. But I looked at a few and they all seem to have it. What I'm less clear about is if that string is guaranteed to appear only at the end. The OP seems to think so, but I'm not sure. Still, it is perhaps unlikely that ftp transfer would stall at exactly that point. So the technique might be good enough.

I like the flag file idea personally. Transfer a data file. Then transfer a zero-length "done" file. When the second file arrives, the first is clearly finished.
# 9  
Old 12-22-2003
You lost me on that one. Transfer a zero-data file to indicate the file is complete?

Let me go back to an earlier assumption, EOF at the end of PDFs. I've found many PDFs that have two EOF strings. Looking at a very small sample (30 PDFs), more than half had two EOF strings. I have no idea what the implications are of this. So it makes me want to do a reverse text search on the file for the same string (which can be made even more concrete, as the EOF is always "%%EOF". %% because it's binary? I dunno). Something that can be done in a text editor, but not in a grep search.

Like I mentioned before, the only other method I can think to do this is to do a cyclical check on file size until file size is the same between checks. This isn't bullet proof, either, as an FTP upload could timeout, drop connection, and leave a partial file. I guess I could do the file size check, then double-check it with the %%EOF search.

To be really specific, I work for a newspaper that has commercial printing clients that upload their print jobs via FTP. We then auto. download those PDFs to our RIPs for processing. With this method we remove hours of manual labor checking for and moving files, not to mention cut deadline times to a minumum and allow clients to upload files late into the night without having to have staff scheduled on our end. We currently do this on Apple hardware, some running OS X, others not, all using Apple Scripts and some pretty crappy proprietary software from a newspaper-specific software company. It's less than perfectly reliable for a process that needs to be 99% reliable... so I figured a shell script in OS X would make a great deal more sense.

I'm sure nobody wanted to know that much...
# 10  
Old 12-22-2003
mfilby, the second zero-length file (a file with nothing in it) will only be transferred when the first file is completely finished transferring... therefore if you receive that second file, the first must've been received too.

your explanation of why you're doing this actually helps. now that you've explained more, it sounds like that would require your customers to send their pdf file and then send a second empty file which is probably not practical for them.
# 11  
Old 12-22-2003
It's good to have a reason to be long-winded. Sometimes it's better to explain what you're actually trying to do than ask help for a solution that solves the wrong problem.

What about a combination of cyclical file-size checks, then check for %%EOF to remove the possibility of a partial file left from a disconnected FTP session or timeout?

I've always approached this with the method that once the file is uploaded and complete, it gets moved to a second "temp" directory that is checked by a local wget or curl script where it's downloaded from without a check.
# 12  
Old 12-22-2003
If you're simply doing a one-sided crc, that's silly. You could just loop checking the file length until that seems stable. If you can get the client to do a crc and send that to you then you compare the crc's to see if they're the same. That is actually a great solution. And if they send you a file length and a crc, that is even better.

But the flag file is so simple... Instead of
put some.pdf
your client does a
put some.pdf
put done
There is much less chance of the client making an error with a simple procedure like that.

I have to say that I don't like the check for EOF string idea, First I still believe that it can appear earlier in the file. But more importantly, someday you will need to handle a *.doc or *.txt or a *.rtf or something else. And your script will need to be quickly changed to what I am now suggesting. Change happens very fast in this business.
# 13  
Old 12-22-2003
I like the EOF file idea since I think it's clumsy to expect clients to upload a separate data file that they have no real interest in. It's one more requirement that's out of my control and another responsibility for an unsophisticated user (my apologies, they're really quite intelligent but wouldn't give 2 nickels about a separate data file). The idea is to make things simple for the client. They shouldn't have to do anything different.

I've been reviewing Adobe's PDF format reference, and indeed %%EOF can appear numerous times in the file and yet not truly indicate the end of a file. However, %%EOF will always be in the last 1024 bytes of the file:

3.4.4, ÒFile TrailerÓ
17. Acrobat viewers require only that the %%EOF marker appear somewhere
within the last 1024 bytes of the file.

So again, if I had anyway, even from the host of the ftp site, to scan a directory for files containing a %%EOF, beginning the search from the "theoretical" end of the file, I'd be a happy camper. Something as simple as "fgrep -l /path/*.pdf", only recursively, and then set the resulting filenames to a variable that I could then process with mv or cp.

I'm I being to simplistic? Take it easy on me, I'm from the Apple World of GUI ignorance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automating an interactive process with EOF string

Hello, I'm running Stockfish chess engine ( Home - Stockfish - Open Source Chess Engine ) CLI on Linux in interactive mode which is working fine. root@ubuntu1950x:~# ./stockfish Stockfish 080218 64 POPCNT by T. Romstad, M. Costalba, J. Kiiski, G. Linscott setoption name Debug Log File... (2 Replies)
Discussion started by: prvnrk
2 Replies

2. Shell Programming and Scripting

Can't find string terminator "`" anywhere before EOF

// AIX 6.1 What I am trying to accomplish is to display the user name and the last login date and time in one line: for usrlist in $(cat alluser.txt) do $usrlist perl -e 'print scalar localtime `lsuser -a time_last_login $usrlist | awk -F '=' '{print $2}'`' done However, it... (8 Replies)
Discussion started by: Daniel Gate
8 Replies

3. Programming

Find parent process (not process ID)

Hi: I have a program written in FORTRAN running on AIX platform. It is because missing of documentation and without root password, therefore we want to modify the program so that we can find out which script/program that call this FORTRAN program. I have google for few days, all of them are... (3 Replies)
Discussion started by: cstsang
3 Replies

4. Solaris

Cant find Unix process with ps -ef

Hi All, Heres a little background. We have essbase installed on a solaris server. We are running a report script. The script starts and runs ok.. 1. after some time if i do the ps -ef i can see the process, and it generally completes successfully. 2. Most of the times, when i do the ps with... (2 Replies)
Discussion started by: noufalshaw
2 Replies

5. Shell Programming and Scripting

confused with << EOF EOF

Hi friends , I am confused with << EOF EOF Most of the cases I found sqlplus $db_conn_str << EOF some sql staments EOF another exapmle is #!/bin/sh echo -n 'what is the value? ' read value sed 's/XXX/'$value'/' <<EOF The value is XXX EOF (1 Reply)
Discussion started by: imipsita.rath
1 Replies

6. Programming

How to find if a process a daemon ?

I have a scenario where I need to find if a process is a daemon process or not. This check needs to be done from within the process. I know there are no direct API's to do so. I have explored these options. 1. ctermid() - this can be unsuccessful as per the man pages 2. int devtty; if ((devtty... (7 Replies)
Discussion started by: vino
7 Replies

7. Shell Programming and Scripting

How to find EOF character in a Shell ?

Hi, I'm need to determine if a file contains the EOF character, how can I do that in Shell scripting? Regards. (1 Reply)
Discussion started by: jfortes
1 Replies

8. AIX

find file with process ID

hello I have a process ID and i want to known what files are use with this process. fuser give to me the process with a file...i search a similar command but the reverse: to know the files with a process thank you (1 Reply)
Discussion started by: pascalbout
1 Replies

9. Solaris

How to find which process is using up too much CPU

Hi, I need to find which processes are hogging the cpu up. please advise. Thanks (1 Reply)
Discussion started by: 0ktalmagik
1 Replies

10. Shell Programming and Scripting

how to find the chid process id from given parent process id

how to find the chid process id from given parent process id.... (the chid process doesnot have sub processes inturn) (3 Replies)
Discussion started by: guhas
3 Replies
Login or Register to Ask a Question