Bash script to take a screenshot and upload it to a server every 1s
1
vote
1
answer
758
views
Operating system: Xubuntu
I'm trying to create a bash script that takes a screenshot of my screen and uploads the resulting file to a server. I tried many ways and even asked ChatGPT but still can't find a working solution. Could you please point me to the right direction? Thanks
This is the code I am using
#!/bin/bash
# Set the FTP server hostname or IP address
FTP_SERVER=xxx
# Set the FTP username and password
FTP_USERNAME=xxx
FTP_PASSWORD=xxx
# Set the local and remote file paths
LOCAL_FILE=/home/nicola/screenshot.png
REMOTE_FILE=/public_html/screenshots/screenshot.png
# Connect to the FTP server and log in
ftp -inv $FTP_SERVER << EOF
user $FTP_USERNAME $FTP_PASSWORD
# Send the file
put $LOCAL_FILE $REMOTE_FILE
# Quit
bye
EOF
The file is correctly sent, now I need to repeat the operation once every second but the connection to the server should not be repeated I guess, so it should stay outside the loop.
The files will not be overwritten, I intend to use Date or Time and append it to the filename
Asked by Nicola
(123 rep)
Dec 20, 2022, 11:38 PM
Last activity: Dec 21, 2022, 10:00 AM
Last activity: Dec 21, 2022, 10:00 AM