Last active
          November 22, 2024 11:29 
        
      - 
      
- 
        Save populov/4b740d8de8c8951fb997f9e67bd3fdec to your computer and use it in GitHub Desktop. 
    Flameshot + upload screenshot to SFTP
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # Prerequisites: | |
| # * flameshost (Take screenshot + basic edit): https://flameshot.org | |
| # * scp (OpenSSH/SFTP file copy client) https://www.mankier.com/1/scp | |
| # * notify-send (Desktop notifications) https://ss64.com/bash/notify-send.html | |
| # * xclip (copy to clipboard) https://opensource.com/article/19/7/xclip | |
| # | |
| ## Install prerequisites (Ubuntu): | |
| # sudo apt-get install flameshot openssh-client notify-send xclip | |
| # | |
| # Uncomment last line to delete screenshot file after upload | |
| PORT=2221 | |
| USER="SergeyPopulov" | |
| SFTPSERVER="jing.saritasa.com" | |
| STORAGE=~/Pictures/Screenshots | |
| PASSWORD=oh-noooooooo | |
| #STORAGE=/tmp | |
| RND=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-8} | head -n 1) | |
| DATE=$(date +%Y-%m-%d_%H-%M) | |
| FILE=$DATE"_"$RND".png" | |
| flameshot gui --raw > $STORAGE/$FILE | |
| if [[ ! -s $STORAGE/$FILE ]]; then | |
| rm $STORAGE/$FILE | |
| exit 0 | |
| fi | |
| echo "$FILE created!" | |
| scp -i ~/.ssh/interesnee -P $PORT -o PasswordAuthentication=no -o PubkeyAcceptedKeyTypes=+ssh-rsa $STORAGE/$FILE ${USER}@${SFTPSERVER}:/ | |
| #sshpass -p $PASSWORD scp -vvv -P $PORT -o PasswordAuthentication=yes $STORAGE/$FILE ${USER}@${SFTPSERVER}:/ | |
| if [ $? -ne 0 ]; then | |
| notify-send --icon terminal --category 'transfer.error' "Screenshot upload error" "Could not upload $FILE to $SFTPSERVER" | |
| else | |
| URL="https://${SFTPSERVER}/${USER}/${FILE}" | |
| echo $URL | xclip -selection clipboard | |
| notify-send --icon flameshot --category 'transfer.complete' --expire-time 10 "Screenshot uploaded" "$URL copied to clipboard" | |
| fi | |
| # rm $STORAGE/$FILE | 
thanks for this awesome script !
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Thank you for sharing the gist. I suggest to add a few more
{}for example aroundPASSWORDbecause the password or the filename may include space. An alternative for the nice RND line would be the usage of mktemp https://www.gnu.org/software/coreutils/manual/html_node/mktemp-invocation.html#mktemp-invocation