Advertisement
n8henrie

Service to Upload Images to WordPress Server via SSH

Jan 18th, 2013
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #!/bin/bash
  2. set -e
  3.  
  4. #Originally posted at http://n8henrie.com/2013/01/automator-shell-script-uploading-images-to-wordpress-server
  5.  
  6. ## This script was made as a service in Automator, may need adjustments to function otherwise.
  7. ## Look for portions that need to be replaced with your info, as denoted by [*stuff*]
  8.  
  9. for f in "$@"
  10. do
  11. ## fix up the filename by removing spaces and special characters, prepend date
  12. filename=$(date +"%Y%m%d")_$(basename "$f" | tr -d ' ' | sed 's/[^A-Za-z0-9._-]/_/g')
  13.  
  14. ## Copy the file to uploads folder in /year/month subdirectories.
  15. scp -P [*your server's ssh port number*] -p "$f" [*your ssh user*]@[*your domain*].com:[*path to your uploads folder, starting with /*]/wp-content/uploads/$(date +%Y)/$(date +%m)/$filename
  16.  
  17. ## Make a string with all the urls (necessary if used with multiple files), close the for loop
  18. pasteMe+="http://[*your domain*].com/wp-content/uploads/$(date +%Y)/$(date +%m)/$filename"'\n';
  19. done
  20.  
  21. ## Get rid of final newline and copy the string with the http path(s) to the clipboard
  22. echo -e $pasteMe | perl -0777 -pe 's|\n+\z||ims' | pbcopy
  23.  
  24. ## Shoot a growl notification that it worked.
  25. msg="Looks like the file(s) uploaded successfully to"$'\n\n'$(pbpaste)$'\n\n'"and the URL(s) copied to the clipboard.";
  26. /usr/local/bin/growlnotify "n8upload" -m "$msg";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement