20101115 (the date thar the file arrive) and 1800 (it seems that the file always arrive at the same time 1800)
the date will be the sysdate (20101115)
Afrer I capture the file I need it to encrypted then save it in a directory (archieves), again I can have more than one file in a giving day
Make a directory for each of: incoming, decoded already and the decoded outputs. Maybe an error directory for failures.
email about failures is nice, and a daily email report of decodes.
Run the scripts on cron.
Use fuser to ensure the file is not already being decoded by a process of the last cron interval, or still being downloaded.
(
cd incoming
for f in *
do
if [ "$(fuser #f 2>/dev/null)" != "" ]
then
echo $f is in use.
continue
fi
(decode <$f >../output/$f.decoded
if [ $? = 0 ]
then
mv $f ../processed/$f.done
else
echo error decoding $f
fi
) &
done
)
Not, the file is like this
dailypayments_sfs_payment_201011151800.dat
where 1800 is always the time (6pm) and 20101115 (date) yyyymmdd
and this is dailypayments_sfs_payment (always the same name)
It can be more than one file in there...
---------- Post updated at 11:13 AM ---------- Previous update was at 08:27 AM ----------
What about this: (sorry new at this stuff),
I don't have to move the process file to another directory there is another process that will do that, I just to encrypt the file and leave in the $LocalDir, so the other process will take over
will this work? do the encryption?
# Start Decrypt Process
# Determine if there is a file to process
$FileName find . -type f -name "*.dat.pgp" >/dev/null 2>&1
if [$? !=0]
then
exit
fi
for $FileName in *
do
if [ "$(fuser $FileName 2>/dev/null)" !="" ]
then
echo $FileName is in use
continue
fi
( -gpg -o #FileName -d > $LocalDir
if [ $? = 0]
then
echo file decrypted
else
echo error decoding $FileName
fi
) done
# End of Decrypt process
Use the Code tags button left of <> above so it looks like this:
$!/usr/bin/ksh
.
.
.
# Start Decrypt Process
# Determine if there is a file to process
for $FileName in *.dat.pgp
do
if [ "$FileName" = '*.dat.pgp' ] # no files
then
exit
fi
if [ "$(fuser $FileName 2>/dev/null)" !="" ]
then
date "+%Y-%m-%d %H:%M:%S $FileName is in use"
continue
fi
gpg -o #FileName -d > $LocalDir
if [ $? = 0]
then
else
date "+%Y-%m-%d %H:%M:%S error decoding $FileName"
fi
done
Find is overkill if the files are all in one or a few directories. I never liked the find -exec option, as you do not have good error handling when unattended. You can "find | while read f ; do done" and check for errors, have a separate log for each conversion, etc. Not sure what "$FileName find" does! You can detect unexpanded wild cards easier as above. Not sure what the gpg command line is up to, but most of the line is a weird #comment, work on that. You, too deserve structural indentation and blank lines for easy visual separation of complex constructs.
spinel:/home/nelnet$ sh payfile_decrypt2.shl 'PRCT'
payfile_decrypt2.shl[31]: LocalDir: not found.
payfile_decrypt2.shl[41]: FileName: not found.
payfile_decrypt2.shl[84]: $FileName: This is not an identifier.
when I do this from the command line
cd /home/nelnet/NBS_banner_kit/banner/eodrec_component
it brings me to the right directory
This is what I have
LocalDir = "cd /home/nelnet/NBS_banner_kit/banner/eodrec_component";
FileName = ls *1800*.dat.pgp;
#-------------------------------------------------------------------------------#
# Start Decrypt Process
# Determine if there is a file to process
for $FileName in *.dat.pgp
do
if [ "$FileName" = '*1800*.dat.pgp' ] # no files
then
exit
fi
if [ "$(fuser $FileName 2>/dev/null)" !="" ]
then
date "+%Y-%m-%d %H:%M:%S $FileName is in use"
continue
fi
gpg -o #FileName -d > $LocalDir
if [ $? = 0]
then
"Sucess decrypting the file"
else
date "+%Y-%m-%d %H:%M:%S error decoding $FileName"
fi
done
if [ $? = 0]
then
echo "Sucessfully decoding File Name:" $FileName >>${LF1} 2>>${lf2}
mailx -s "sucesfully decode the file: " $FileName $EMAIL_ADDRS < ${LF1}
else
echo "Error decoding file Name:" $FileName >>${LF1} 2>>${lF2}
mailx -s "Error decoding File:" $FileName $EMAIL_ADDRS < ${LF1}
fi
done
when I execute this from the command line
ls *1800*.dat.pgp;
I get the right file, the one that I want to decrypt