2

I have two directories: dir1 and dir2 In dir1 I have files like:

  • blacklist1.dat.bz2
  • blacklist2.dat.bz2
  • blacklist3.dat.bz2

and so on.

In dir2 I have encrypted files like:

  • blacklist1.dat.bz2.enc

I would like to encrypt all the files that (comparing dir1 with dir2) doesn't exist on dir2. For encrypt a file I use Openssl: - openssl enc -aes-256-cbc -in dir1/file -out dir2/file.enc -k Password

I did like this but I'm missing the condition of the if

for i in /dir1/*; do
   name=$(basename "$i")
   test=$name.enc
   if [ **<$test doesn't exist on dir2>** ]; then
      openssl enc -aes-256-cbc -in dir1/name -out dir2/name.enc -k Password
   fi
done
2
  • So, your question is "how to test for file existence" ? Have you tried google ? Commented Dec 20, 2016 at 16:14
  • Sorry, I realized my question was a bit stupid.
    – LucaP
    Commented Dec 20, 2016 at 16:32

1 Answer 1

0

I was going to recommend trying to use something like rsync to determine a list of files missing/different and then use that listing. However, that wouldn't easily work with your needs.

You may also want to consider using find to help with possible recursion. Even diff'ing files from the 2 directories with some sed and grep commands could give you the file listing you want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .