Advertisement
goebelmasse

Mein Blogskriptchen (verwendet wpcmd)

Nov 28th, 2018
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.63 KB | None | 0 0
  1. #!/bin/sh
  2. ########################################################################
  3. #
  4. # BlogDir
  5. # $Id: blogdir,v 1.2 2014/09/27 22:18:13 elias Exp $
  6. #
  7. # An example shell script for wpcmd.
  8. # Copyright (c) 2010-2012 Elias Schwerdtfeger
  9. #
  10. # Just blog all the files from a directory and archive the postings
  11. # and successfully uploaded files in an archive directory.
  12. #
  13. # Requires at least wpcmd 0.05
  14. #
  15. # This program is free software; you can redistribute it and/or modify
  16. # it under the terms of the GNU General Public License as published by
  17. # the Free Software Foundation; either version 2 of the License, or
  18. # (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program; if not, write to the Free Software
  27. # Foundation, Inc., 59 Temple Place - Suite 330,
  28. # Boston, MA 02111-1307, USA.
  29.  
  30. ########################################################################
  31. #
  32. # Configuration
  33. #
  34. ########################################################################
  35.  
  36. # This is the path of the directory containing the texts to
  37. # blog. As you can see in this example, you can easily organize
  38. # your postings in the file system by giving the directories
  39. # names created from the date...
  40. blogdir=~/Dokumente/Blogtexte/`date +%Y-%m`
  41.  
  42. # Subdirectory for published postings, created automatically
  43. archdir=Published
  44.  
  45. # Subdirectory for failed postings, created on first failure
  46. faildir=Failed
  47.  
  48. # Log file
  49. logfile=wpcmd.log
  50.  
  51. # The wpcmd command
  52. # This can remain unchanged in all normal installations...
  53. wpcmd=wpcmd
  54.  
  55. ########################################################################
  56. #
  57. # Program
  58. #
  59. ########################################################################
  60.  
  61. export PATH=/bin:/usr/bin:/usr/local/bin
  62. errcount=0
  63. echo blogdir publishes texts from $blogdir
  64. cd "$blogdir"
  65.  
  66. # Creating separate archive directories for every day to avoid
  67. # filename collisions
  68. dayarchdir=$archdir/`date +%y-%m-%d`
  69.  
  70. # Just a newline, filenames of uploaded files may contain spaces...
  71. IFS='
  72. '
  73.  
  74. retval=0
  75. outp=/tmp/blogdir.$$
  76. trap "rm -f $outp; exit" 1 2 15
  77.  
  78. for file in *.txt
  79. do
  80.     if grep -q '^!![[:space:]]*blog:' "$file"
  81.     then
  82.         if $wpcmd -l $logfile -f $outp "$file"
  83.         then
  84.             echo $file published, wpcmd output follows
  85.             nl -s ": " $outp
  86.             test -d "$archdir" || mkdir "$archdir"
  87.             test -d "$dayarchdir" || mkdir "$dayarchdir"
  88.             if grep -q '^INFO: Uploading' $outp
  89.             then
  90.                 mv `grep '^INFO: Uploading' $outp |
  91.                     sed 's/^[^"]*"//
  92.                         s/"[^"]*$//'` "$dayarchdir"
  93.                 echo Uploaded files archived to $dayarchdir.
  94.             fi
  95.             mv "$file" "$dayarchdir"
  96.             echo $file archived to $dayarchdir.
  97.         else
  98.             echo $file failed, wpcmd output follows
  99.             nl -s ": " $outp
  100.             test -d "$faildir" || mkdir "$faildir"
  101.             mv "$file" "$faildir"
  102.             echo $file moved to $faildir.
  103.             retval=1
  104.             errcount=`expr $errcount + 1`
  105.         fi
  106.         rm -f $outp
  107.     fi
  108. done
  109. if test $errcount -gt 0
  110. then
  111.     echo
  112.     echo "$errcount error(s) occured. Please check $faildir" 1>&2
  113. fi
  114. exit $retval
  115.  
  116. ########################################################################
  117. #
  118. # CODE IS PROSA, NOT POETRY
  119. #
  120. ########################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement