On my website I host a lot of files, and when people view the site, currently each time the page loads, I have PHP generating the md5 sums for the files right then and there. It was fine when my site was small, but now that's obviously very inefficient. Now I'd like to start generating MD5 sums when a user uploads a file, and storing it in a text file along with other information to be read from there instead.
I know how to incorporate this into my PHP script, however I still have the problem of the hundreds of files that have already been uploaded, that won't have MD5 information stored in their .desc file.
The .desc file already stores certain information such as username, IP, and a file description. I want to append the md5 information to the end of the .desc file. The .dlcnt file is irrelevant, it stores amount of times downloaded.
So basically I'm trying to write a bash script to do this. Trouble is... I know squat about bash scripting!
All I've been able to come up with so far is this:
I'm sure this is a really horribly inefficient way to do this, but it's all I know.
First problem is that a lot of the directories and files have spaces in them. That screws up the script right there. I don't know how to change the names to have a \ in them.
Second problem is I'm not exactly sure how to output the md5sum to the .desc file. Obviously what I have written up there doesn't work, it's not proper use of the variable... but I'm not sure what to do?
Can anyone give me a hand?
Last edited by GrdLock; 10-23-2010 at 12:28 AM..
Reason: Solved
find and xargs are good friends; one finds files and prints them, the other converts lines into command arguments. They're such good friends they even have a mutually-agreed-on format for communicating names into xargs without messing up on spaces: nulls. -print0 will tell find to print using nulls as seperators, and --null will tell xargs to read them likewise.
You can specify more than one extension with find's -or option, as well.
And, wherever you have 'for LINE in `cat file` you can do 'while read LINE ; do something ; done < file', much more efficient. It can also read from a pipe.
So you can cram this all into one efficient statement:
find seems to need brackets around the things in -or to use it both, otherwise it just ends up looking for the last one.
Last edited by Corona688; 10-23-2010 at 12:44 AM..
Reason: needed more brackets
EDIT: Ok, I see you modified your original post, let me give that a shot.
Thanks for the reply.
Ok, I did:
Which returns:
The syntax of the find command isn't working. So just for testing purposes I took out the -or switches and tried it just for .zip files, and it worked, it outputted the md5's of the .zip files, however, I'm not sure how I would write those md5's to the .desc files using your example, instead of just outputting them?
---------- Post updated at 10:03 PM ---------- Previous update was at 10:02 PM ----------
Ok, wow, that's working.
The only problem is for some reason the -or switch isn't working. It still says "find: paths must precede expression: *.apk" for anything with the -or option.
That's really no big deal though, you're been more than helpful already! It won't take too much extra time to make a script for each file extension, or just run it multiple times or something.
Either way I really appreciate the help. Also, thanks for the explanation of how everything works as well!
Hello All,
May i please know how do i ensure my split command would NOT generate incomplete output files like below, the last lines in each file is missing some columns or last line is complete.
split -b 50GB File File_
File_aa
|551|70210203|xxxxxxx|12/22/2010 20:44:58|11/01/2010... (1 Reply)
Hi All,
What am trying to do is generate the report by compating two files.
File A
-----------
111 22222 3333
222 55555 7777
File B
-----------
11A 22222 3333
333 55555 7778
Now the report should be as follows
Added:
333 55555 7778
Removed: (6 Replies)
Hi,
I have a series of data files for which I wish to plot using "splot". Say, the files names are like:
950_data,951_data,952_data,......1000_data.
For one file , say to plot 950_data, i write following lines into a single file and load it in the gnuplot as :
gnuplot> load 'plot'
... (6 Replies)
Hello everyone,
I am looking to basically creating md5sum files for all iso files in a directory and archive the resulting md5 files into a single archive in that very same directory.
I worked out a clumsy solution such as:
#find files for which md5sum are to be created and store the... (1 Reply)
I have a script which generates recursively some files in folders for a given root folder.
I have checks for permissions and it works for all folders except one(i have 777 permission on it). When i try calling the script in problematic folder(problematic folder being root folder), script works as... (2 Replies)
Hello:
First, I have no idea what to search for on this task, so I'll just spell it out.
I have the Bible in Audio format and each book is in a directory of it's own.
01 to 66 accordingly.
I need a script to walk through each of them and ls *.mp3 > directory|book.m3u without the preceding... (2 Replies)
Hi all,
Have to generate an xml having information related to files in the directory
Suppose i have file
file1.xml (datafile)
file2.xml (datafile)
file3.xml (metafile)
Now i need to generate an xml in the format >>
<?xml version="1.0" encoding="UTF-8"?>
<AuditFile Version="2.0">... (8 Replies)
Given that I have a log file of the format:
DATE ID LOG_LEVEL | EVENT
2009-07-23T14:05:11Z T-4030097550 D | MessX
2009-07-23T14:10:44Z T-4030097550 D | MessY
2009-07-23T14:34:08Z T-7298651656 D | MessX
2009-07-23T14:41:00Z T-7298651656 D | MessY
2009-07-23T15:05:10Z T-4030097550 D | MessZ... (5 Replies)
I/P file name:- 20092008.txt
Check number of entries in i/p file by following command
ChkEnt -infl 20092008.txt -opfl 20092008_test.txt >count.txt
Dear Friends,
Please help me in automating following thing.
If output generated (count.txt) is having value more than 1000 i.e.... (8 Replies)
I've been working on getting a script to take size, dir name and file name variables from an input file and creating the same dir structure along with the file of specific size.
An example of the input file:
size/dirname/filename
2100/JAN_06/12345ABC.TCC
2354/FEB_06/24564XYZ.NOS... (2 Replies)