0

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?

4
  • Why not use one of many backup programs that are available? Here is an example. Déjà Vu offers an intuitive, transparent, and reliable way to back up your data. It's a preference pane that lives in your System Preferences, and it allows you to schedule unattended backups of important folders, or even your entire system. With Déjà Vu, you can: Make a full, bootable copy (or "clone") of your disk.
    – David
    Commented 2 days ago
  • It is not really a backup program, but a certificate service. It is easier to explain it as a backup program rather than mixing in certificates, SSL/TLS and what not.
    – Europa
    Commented 2 days ago
  • An answer is only as good as the info in the question. Missing info equals bad answer.
    – David
    Commented 2 days ago
  • You are almost certainly better off using a here-document rather than trying to stuff quoted strings within quoted strings. See for example Write a file in the middle of a shell script Commented 2 days ago

0

You must log in to answer this question.

Browse other questions tagged .