writing script to create backup of file by adding datetime to file name. Basically test for file presence
if there, cp with datetime
then rm original
cp works fine from command line but get
cannot stat `full path to file': No such file or directory
Code:
#!/bin/bash
base_dir='~/html/'
for a in CVP_dadamail; do
ldir='/.dada_files/.logs/'
f_name='errors.txt'
f2bu=$base_dir$a$ldir$f_name
dt1="$(date +%Y%m%d%H%M%S)"
backup="$base_dir$a$ldir$dt1.$f_name"
if [ -f $f2bu ]; then
cp $f2bu $backup
rm $f2bu
fi
done
here are the errors:
cp: cannot stat `~/html/CVP_dadamail/.dada_files/.logs/errors.txt': No such file or directory
rm: cannot remove `...': No such file or directory
The for statement is a placeholder as I have same file to backup out of several directories.
using "bash -x scriptname" -OR- inserting echos, I can see I've constructed the strings properly. Believing it might be related to the hidden directories, I tried setting the shopt "glob" options to no avail.
Ultimately I'll add the other directories to the for loop and then run this from a cron job, so if you see potential pitfalls knowing I'm headed in that direction...
believe construct would be
Code:
for a in dir1 dir2 dir3; do
Thanks for looking...