Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

variable in scp filename not working?

Tags:

bash

scp

I'm trying to scp a backup tgz file from one server to another every night. The backup script uses the following $date var just fine but when I modify it slightly for scp it breaks:

#!/bin/sh
date=`date +%Y-%m-%d`
rbfile=`/backups/$date_00h00.tgz`
scp $rbfile user@myserverip:

But the script dies with the error:

/backups/.tgz: No such file or directory

On a side note, I really should switch to rsync for better remote backups - the tgz files are at 3.5GB now. Any recommended tutorials?

like image 710
helion3 Avatar asked Oct 09 '22 06:10

helion3


1 Answers

when using $date_00h00 you tell bash to use the variable named date_00h00, because letters, numbers and _ characters are allowed as variables names.

Enclose the variable name in {} and it will correct the problem :

rbfile=`/backups/${date}_00h00.tgz`
like image 66
Cédric Julien Avatar answered Oct 13 '22 12:10

Cédric Julien