<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.1701technology.com/index.php?action=history&amp;feed=atom&amp;title=Process_new_or_changed_files</id>
	<title>Process new or changed files - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.1701technology.com/index.php?action=history&amp;feed=atom&amp;title=Process_new_or_changed_files"/>
	<link rel="alternate" type="text/html" href="https://wiki.1701technology.com/index.php?title=Process_new_or_changed_files&amp;action=history"/>
	<updated>2026-05-06T14:41:00Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>https://wiki.1701technology.com/index.php?title=Process_new_or_changed_files&amp;diff=530&amp;oldid=prev</id>
		<title>Michael.mast: Created page with &quot;In this example I check for all files in a source directory, create an MD5 hash, search for the hash in a database, if not found add the file to the database, copy the file to...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.1701technology.com/index.php?title=Process_new_or_changed_files&amp;diff=530&amp;oldid=prev"/>
		<updated>2017-10-04T18:45:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;In this example I check for all files in a source directory, create an MD5 hash, search for the hash in a database, if not found add the file to the database, copy the file to...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;In this example I check for all files in a source directory, create an MD5 hash, search for the hash in a database, if not found add the file to the database, copy the file to the destination, send an email with a list of files that were processed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
newfilesdate=$(date +%Y-%m-%d)&lt;br /&gt;
mkdir /tmp/workingdir&lt;br /&gt;
find /mnt/source/ -type f &amp;gt; /tmp/woringdir/filelist&lt;br /&gt;
while read line&lt;br /&gt;
do&lt;br /&gt;
	line2=$(md5sum &amp;quot;$line&amp;quot; | sed 's/\ /---/' | sed 's/\ //')&lt;br /&gt;
	date=$(ls -l --time-style=&amp;quot;+%Y-%m-%d&amp;quot; &amp;quot;$(awk 'BEGIN {FS=&amp;quot;---&amp;quot;}; {print $2}' &amp;lt;&amp;lt;&amp;lt;&amp;quot;$line2&amp;quot;)&amp;quot; | awk '{print $6}')&lt;br /&gt;
	hash=$(awk 'BEGIN {FS=&amp;quot;---&amp;quot;}; {print $1}' &amp;lt;&amp;lt;&amp;lt;&amp;quot;$line2&amp;quot;)&lt;br /&gt;
	filename=$( echo &amp;quot;$(awk 'BEGIN {FS=&amp;quot;---&amp;quot;}; {print $2}' &amp;lt;&amp;lt;&amp;lt;&amp;quot;$line2&amp;quot;)&amp;quot; | sed &amp;quot;s|.*/||;s|\ |\\\ |g;s|&amp;quot;\'&amp;quot;|\\\'|g&amp;quot;)&lt;br /&gt;
	moddate=$(awk 'BEGIN {FS=&amp;quot;---&amp;quot;}; {print $3}' &amp;lt;&amp;lt;&amp;lt;&amp;quot;$line2&amp;quot;)&lt;br /&gt;
	query=&amp;quot;$( echo &amp;quot;use database_name; select * from table_name where MD5 = '$hash';&amp;quot; | mysql -u user_name)&amp;quot;&lt;br /&gt;
	if ! grep -qi $hash &amp;lt;&amp;lt;&amp;lt;$query; then&lt;br /&gt;
	        echo &amp;quot;use database_name; insert into table_name (name,mod_date,move_date,MD5) values ('$filename','$newfilesdate','$date','$hash');&amp;quot; | mysql -u user_name&lt;br /&gt;
	        cp &amp;quot;$line&amp;quot; /mnt/destination/&lt;br /&gt;
	        echo &amp;quot;$line&amp;quot; &amp;gt;&amp;gt; /tmp/workingdir/copied&lt;br /&gt;
	fi&lt;br /&gt;
done &amp;lt; /tmp/workingdir/filelist&lt;br /&gt;
if [ -a /tmp/workingdir/copied ]; then&lt;br /&gt;
        sed -i 's|^.*\/||g' /tmp/workingdir/copied&lt;br /&gt;
        echo &amp;quot;Subject: &amp;quot;Files copied&amp;quot; | cat - /tmp/workingdir/copied | /usr/sbin/sendmail -r your_relay_email@domain.tld youremail@domain.tld&lt;br /&gt;
fi&lt;br /&gt;
rm -rf /tmp/workingdir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Michael.mast</name></author>
		
	</entry>
</feed>