I have a folder that I want to zip a directory, then upload it to a web server with curl.
- Backup folder: /opt/ladapter/data
- Zip File: /opt/ladapter/cert_$date_ymd.zip
Bash script:
cert_script="#!/bin/bash
# Variables
echo \"VARIABLES\"
date_ymd=\$(date +\"%Y-%m-%d\")
# Zip
echo \"ZIP\"
rm -f /opt/ladapter/cert_*.zip
zip -r \"/opt/ladapter/cert_\$date_ymd.zip\" /opt/ladapter/data
# Upload
echo \"UPLOAD CERT\"
curl --location 'https://my-api.com/upload' \
--header 'Authorization: super-secret-password' \
--form 'file=@\"/opt/ladapter/backup_\$date_ymd.zip\"'
"
echo "$cert_script" | tee -a /opt/ladapter/cert_script.sh
chmod +x /opt/ladapter/cert_script.sh
/opt/ladapter/cert_script.sh
This gives me the following error:
curl: (26) Failed to open/read local data from file/application
The zip file exists, but my guess is that bash does not find the cert_2024-06-26.zip file because of escaping inside quotes?