jllort wrote:ocaselvaggia can share the script on wiki ? could be useful to other usersYes, sure!
Where and how to make it?
jllort wrote:ocaselvaggia can share the script on wiki ? could be useful to other usersYes, sure!
#!/bin/bash
if [ -f /var/run/okmScanCron.pid ]; then
echo "`date` Scan Cron: Already running, skipping this cycle!"
exit 2
fi
touch /var/run/okmScanCron.pid
for file in /opt/openkm/IMPORT/NEW-Scan/*.pdf; do
if [ -d "$file" ]; then
echo "`date` Scan Cron: Dazed and consufed, \"$file\" is a directory!"
fi
if [ -z "$file" ]; then
rm -rf /var/run/okmScanCron.pid
exit 0
fi
if [ ! -f "$file" ]; then
rm -rf /var/run/okmScanCron.pid
exit 0
fi
if [ -s "$file" ];then
if [ $(/usr/sbin/lsof -t $file | wc -l) -ge 1 ];then
echo "File $file still being written, skipping"
else
hash1=$(md5sum $file)
sleep 5
hash2=$(md5sum $file)
if [ ! "$hash1" = "$hash2" ];then
echo "File $file still being written, skipping"
else
/opt/openkm/import.sh "$file" NEW-Scan
fi
fi
else
echo "`date` Scan Cron: $file is empty!"
fi
done;
rm -rf /var/run/okmScanCron.pid
#!/bin/bash
# JOAKO Import 1.0.2 - Copyright 2011 Andrew Joakimsen
# Distributed under the terms of the GNU General Public
# License Version 2 and no future versions.
#
# Script to import files into OpenKM and report error/success.
# Requires the PHP import script written by snowman, with a
# few small tweaks.
###################################
### ###
### C O N F I G U R A T I O N ###
### ###
###################################
# OpenKM directory where files are imported to
OKM_IMPORT_DIR=NEW
# Filesystem directory (no trailing slash) where we put imported files (it will be created)
STORE_DIR=/opt/openkm/IMPORT/Archive
# Filesystem directory (no trailing slash) where we put files that encountered import errors
ERROR_STORE_DIR=/opt/openkm/IMPORT/Error
####################################
# First let's see if the runtime condition is sane
if [ -z "$1" ]; then
echo "JOAKO Import: Missing file name"
echo "Usage: import.sh [filename] <[target-directory]>"
exit 1
fi
# If ARG1 is a real file
if [ -d "$1" ]; then
echo "ERROR: \"$1\" is a directory!"
exit 1
fi
if [ ! -f "$1" ]; then
echo "ERROR: \"$1\" Invalid file name "
exit 1
else
INFILE=$1
fi
# Check if OKM_IMPORT_DIR was passed as argument
if [ -z "$2" ]; then
OKM_DIR=$OKM_IMPORT_DIR
else
OKM_DIR=$2
fi
# Check if the imported files directory exsists
if [ ! -d $STORE_DIR/$OKM_DIR ]; then
if [ ! -d $STORE_DIR ]; then
mkdir $STORE_DIR
fi
mkdir $STORE_DIR/$OKM_DIR
fi
<?php
$okmurl="http://doc-server/OpenKM/";
$okmid="okmAdmin";
$okmpw="admin";
$impfile = $argv[1];
$filename = $argv[2];
$folder = $argv[3];
$OKMAuth = new SoapClient($okmurl."OKMAuth?wsdl");
$OKMDocument = new SoapClient($okmurl."OKMDocument?wsdl");
// open file and encode if necessary
$handle = fopen($impfile,'rb');
$file_content = fread($handle,filesize($impfile));
fclose($handle);
$encoded = base64_encode($file_content);
// Login
$token = $OKMAuth->login($okmid, $okmpw);
$OKMDocument->createSimple($token,"/okm:root/$folder/$filename",$file_content);
// Logout
$OKMAuth->logout($token);
?>
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.api.OKMDocument;
import java.io.*;
String token = JcrSessionManager.getInstance().getSystemToken();
Session session = JcrSessionManager.getInstance().get(token);
OKMDocument document = OKMDocument.getInstance();
public class OnlyExt implements FilenameFilter {
String ext;
public OnlyExt(String ext) {
this.ext = "." + ext;
}
public boolean accept(File dir, String name) {
return name.endsWith(ext);
}
}
File scans = new File("/home/scanner");
Thread.sleep(10000); // Sleep 10 seconds in case files are still being written
try {
for (File scan : scans.listFiles(new OnlyExt("pdf"))) {
try {
document.createSimple(token, "/okm:root/Scans/" + scan.getName(), new FileInputStream(scan));
scan.delete();
}catch (Exception e) {
print("Exception: " + e);
}
}
} catch (Exception e) {
print("Exception: " + e);
}