K
K
Konstantin2022-04-20 17:15:38
linux
Konstantin, 2022-04-20 17:15:38

Bash error while zipping directory?

Script:

#!/bin/bash
DIRECTORY=$1
NOW=$(date +"%m-%d-%Y")
FILE="backup.tar.gz"
echo "Backing up data, please wait..."
tar -cvf $FILE $DIRECTORY
mv $FILE $NOW


Running from the console:
sh backup.sh mail

I'm trying to add the mail directory to the archive, which lies next to the script.

I get:

tar: mail\r\r: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AVKor, 2022-04-20
@Junart1

#!/bin/bash

directory=$1
now=$(date +"%m-%d-%Y")
mkdir -p "$now"
backup_file="backup.tar.gz"
echo "Backing up data, please wait..."
tar zcvf "$backup_file" "$directory"
mv "$backup_file" "$now"

sh backup.sh mail

If you write in Bash, then
bash backup.sh mail
Or you can make the script executable and
./backup.sh mail

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question