Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ########################################################################
- #
- # BlogDir
- # $Id: blogdir,v 1.2 2014/09/27 22:18:13 elias Exp $
- #
- # An example shell script for wpcmd.
- # Copyright (c) 2010-2012 Elias Schwerdtfeger
- #
- # Just blog all the files from a directory and archive the postings
- # and successfully uploaded files in an archive directory.
- #
- # Requires at least wpcmd 0.05
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place - Suite 330,
- # Boston, MA 02111-1307, USA.
- ########################################################################
- #
- # Configuration
- #
- ########################################################################
- # This is the path of the directory containing the texts to
- # blog. As you can see in this example, you can easily organize
- # your postings in the file system by giving the directories
- # names created from the date...
- blogdir=~/Dokumente/Blogtexte/`date +%Y-%m`
- # Subdirectory for published postings, created automatically
- archdir=Published
- # Subdirectory for failed postings, created on first failure
- faildir=Failed
- # Log file
- logfile=wpcmd.log
- # The wpcmd command
- # This can remain unchanged in all normal installations...
- wpcmd=wpcmd
- ########################################################################
- #
- # Program
- #
- ########################################################################
- export PATH=/bin:/usr/bin:/usr/local/bin
- errcount=0
- echo blogdir publishes texts from $blogdir
- cd "$blogdir"
- # Creating separate archive directories for every day to avoid
- # filename collisions
- dayarchdir=$archdir/`date +%y-%m-%d`
- # Just a newline, filenames of uploaded files may contain spaces...
- IFS='
- '
- retval=0
- outp=/tmp/blogdir.$$
- trap "rm -f $outp; exit" 1 2 15
- for file in *.txt
- do
- if grep -q '^!![[:space:]]*blog:' "$file"
- then
- if $wpcmd -l $logfile -f $outp "$file"
- then
- echo $file published, wpcmd output follows
- nl -s ": " $outp
- test -d "$archdir" || mkdir "$archdir"
- test -d "$dayarchdir" || mkdir "$dayarchdir"
- if grep -q '^INFO: Uploading' $outp
- then
- mv `grep '^INFO: Uploading' $outp |
- sed 's/^[^"]*"//
- s/"[^"]*$//'` "$dayarchdir"
- echo Uploaded files archived to $dayarchdir.
- fi
- mv "$file" "$dayarchdir"
- echo $file archived to $dayarchdir.
- else
- echo $file failed, wpcmd output follows
- nl -s ": " $outp
- test -d "$faildir" || mkdir "$faildir"
- mv "$file" "$faildir"
- echo $file moved to $faildir.
- retval=1
- errcount=`expr $errcount + 1`
- fi
- rm -f $outp
- fi
- done
- if test $errcount -gt 0
- then
- echo
- echo "$errcount error(s) occured. Please check $faildir" 1>&2
- fi
- exit $retval
- ########################################################################
- #
- # CODE IS PROSA, NOT POETRY
- #
- ########################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement