I made a list of directory names in a file HS_client_list
. I need to file the with _zipped_m_
and decrypt and unzip them.
This the script I have written. It works well till decrypt and after that it is not reading the name from HS_client_list
. So, the first external argument is the list of directory names, and the second one will read the list of files within the directory.
What I am attempting is, first cd to the directory from HS_client_list
file and find the .enc
in the directory and pass it to gap.log
file. Then, I need to decrypt and unzip the files one by one.
The issue: Until the decrypt loop it works fine.
#!/bin/bash
while IFS= read -r line; do
echo Executing cd /moveit/$line
cd /moveit/$line
#check if encrypted files exist
if [[ -n "$(ls -A /moveit/$line/*.enc 2>/dev/null)" ]]; then
#find gaps files
find $PWD -type f -iname "*_zipped_m_*.enc" -mmin +5 -execdir basename '{}' ';' >/home/infa91punv/gaps.log
#Creating array
while IFS= read -r line; do
echo Creating loop for encryped files
for m in "${line[@]}"
do
d=$(echo "$m" | cut -f 1 -d '.')
echo $d
d=$d.dat
echo $d
/cerner/extproc/hfencrypt_plus $m $d Decrypt /cerner/extproc/hfsymmetrickey.dat log.log infa91punv
echo /cerner/extproc/hfencrypt_plus $m $d Decrypt /cerner/extproc/hfsymmetrickey.dat log.log infa91punv
if [[ -f "$d" ]]; then
mv $m /cerner/sodaman/enc_archive
echo Moving file to encrypted archive
echo removing log file : rm log.log
rm log.log
else
echo File was not decrypted successfully
fi
done
done < /home/infa91punv/gaps.log
else
echo No encrypted files present
fi
It works fine till this. The below command should put the argument from the HS_client_list
file, but it doesn’t. It is blank.
For instance, the output is (ttest.sh,43+ ls -A '/moveit//zipped_m.dat') it is blank after /moveit//... Where it has to be /moveit/foldername/ from the HS_client_list file.
After using the IFS=
read the second time, the next command is not reading the first IFS read
, it seems.
#check if zipped files exist
if [[ -n "$(ls -A /moveit/$line/*_zipped_m_*.dat 2>/dev/null)" ]];
then
#create array of all zipped files
dat_zipped_files=($( ls *_zipped_m_*.dat ))
echo Creating array for gaps zipped files : $dat_zipped_files
#unzip all zipped files.
for m in "${dat_zipped_files[@]}"
do
echo Unzipping files in array : tar -zxvf $m
tar -zxvf $m
echo Moving file to archive : mv $m /cerner/sodaman/enc_archive
mv $m /cerner/sodaman/enc_archive
echo Increment move indicator by 1
move=$((move+1))
echo Move count is $move
done
else
echo No zipped files present
fi
done < HS_client_list