Reputation: 1
I have a data file, that when a flag file is created, the data file is encrypted. Here is an example of the data file name WSPGLOBAL.PAYMENTS.ISO20022_PAIN_01Ver3.66169592.xml and the flag file name SendPaysource.66169592 . I want to be able to pass the numeric part of the flag file name and only gpg the corresponding data file with that numeric value in the name.
I currently have a working script that does the gpg based on wildcards, but there may be a possibility that there is a second data file that is not ready to be sent and doesnt have the flag file.
#!/bin/bash
. /pbapps/pbmis/apps/apps_st/appl/APPSpbmis_ennycebs02.env
if [ -e /misc/pbmis/output/SendPaysource.* ];
then
gpg --always-trust --no-tty -se --passphrase xxxxxxxxx -r xxxxx.xxxxx.com /misc/pbmis/output/WSPGLOBAL.PAYMENTS.ISO20022_PAIN_01Ver3.*.xml
fi
Any advice is greatly appreciated.
Upvotes: 0
Views: 108
Reputation: 333
As far as I understand it, you want to pass the flag file that corresponds to a data file only if it exists, this code will do the job:
#!/bin/sh
# Change to bash if the .env file has bashisms
. /pbapps/pbmis/apps/apps_st/appl/APPSpbmis_ennycebs02.env
basedir=/misc/pbmis/output
for data in "$basedir/WSPGLOBAL.PAYMENTS.ISO20022_PAIN_01Ver3."*.xml; do
without_ext="${data%%.xml}" # Remove extension
flagnum="${without_ext##*.}" # Extract after '.' (Represents the number part)
flagfile="$basedir/SendPaysource.$flagnum"
# Check if the corresponding flag file exists
[ -e "$flagfile" ] && {
gpg --always-trust --no-tty -se --passphrase xxxxxxxxx -r xxxxx.xxxxx.com "$data"
}
done
Upvotes: 0