Last updated: 10-05-2014 23:21
| << Back | HOME | >> Next |
Here is two scripts one using the soffice (LibreOffice) in headless mode and the other using the unoconv utility. Both scripts convert Word, Excel & Powerpoint documents to the Open Document Formats, then tarball and compress the original files while removing the originals.
$ cat docu-format-conv.sh
#!/bin/bash
# Define variables #
THISFILE=${0##*/}
DOCS="/home/dobriain/Documents"
ORIGMSDOCS="$DOCS/origmsdocs"
STDERR="/dev/null" # or STDERR="$DOCS/$THISFILE.log"
# Make ORIGMSDOCS directory if necessary #
if [ ! -d "$ORIGMSDOCS" ]; then
mkdir $ORIGMSDOCS
fi
# Move original MS files to ORIGMSDOCS directory #
mv $DOCS/*.* $ORIGMSDOCS/
# Convert ms format to odf #
soffice --headless --convert-to odt --outdir $DOCS/ $ORIGMSDOCS/*.doc* &> $STDERR
soffice --headless --convert-to ods --outdir $DOCS/ $ORIGMSDOCS/*.xls* &> $STDERR
soffice --headless --convert-to odp --outdir $DOCS/ $ORIGMSDOCS/*.ppt* &> $STDERR
# tgz the original MS docs and remove the directory #
cd $ORIGMSDOCS
tar -czvf $DOCS/origmsdocs.tgz * &> $STDERR
rm -r $ORIGMSDOCS
# End #
echo "$THISFILE has completed conversion of Microsoft files in $DOCS"
$ ./docu-format-conv.sh
docu-format-conv.sh has completed conversion of Microsoft files in /home/dobriain/Documents.
unoconv is a commandline utility that will convert between document formats. It uses the LibreOffice Universal Network Objects (UNO) component model which is an interoperability tool for convertion between different formats.
$ cat uno-format-conv.sh
#!/bin/bash
# Define variables #
THISFILE=${0##*/}
DOCS="/home/dobriain/Documents"
ORIGMSDOCS="$DOCS/origmsdocs"
STDERR="/dev/null" # or STDERR="$DOCS/$THISFILE.log"
# Make ORIGMSDOCS directory if necessary #
if [ ! -d "$ORIGMSDOCS" ]; then
mkdir $ORIGMSDOCS
fi
# Move original MS files to ORIGMSDOCS directory #
mv $DOCS/*.* $ORIGMSDOCS/
# Convert ms format to odf #
unoconv --format odt $ORIGMSDOCS/*.doc* &> $STDERR
unoconv --format ods $ORIGMSDOCS/*.xls* &> $STDERR
unoconv --format odp $ORIGMSDOCS/*.ppt* &> $STDERR
# Move converted files to UNODOCS directory #
mv $ORIGMSDOCS/*.od* $DOCS/
# tgz the original MS docs and remove the directory #
cd $ORIGMSDOCS
tar -czvf $DOCS/origmsdocs.tgz * &> $STDERR
rm -r $ORIGMSDOCS
# End #
echo "$THISFILE has completed conversion of Microsoft files in $DOCS"
$ ./uno-format-conv.sh
uno-format-conv.sh has completed conversion of Microsoft files in /home/dobriain/Documents.
| << Back | HOME | >> Next |