I am using 7za command to unzip password protected files. Lets consider a scenario, I have one file who's password is a combination of mmyy. dates(mmyy) can be for current month, previous month or previous to previous month. eg 1213 or 1113 or 1013 (mmyy:format) below is a sample code snippet i wrote
function currmonth
{
curr_mon=`echo $(date +%x)`
cyy=`echo $curr_mon| awk '{print substr($0,9,2)}'`
cmm=`echo $curr_mon| awk '{print substr($0,1,2)}'`
curr_pswd=`echo ${yy}${mm}`
}
function prevmonth
{
prev_mon=`echo $(date +%x -d 'last month')`
yy=`echo $prev_mon| awk '{print substr($0,9,2)}'`
mm=`echo $prev_mon| awk '{print substr($0,1,2)}'`
prev_pass=${yy}${mm}
}
function prev2month
{
prev2_mon=`echo $(date +%x -d '2 month ago')`
p2pyy=`echo $prev2_mon| awk '{print substr($0,9,2)}'`
p2pmm=`echo $prev2_mon| awk '{print substr($0,1,2)}'`
prev2mon_pass=${p2pyy}${p2pmm}
}
function IA_oper
{
files=`ls abc*.zip`
for eachfile in $files; do
Not sure after this, here am not sure how do I loop them using If condition
if [expression];then
7za x -p$curr_pass $eachfile
elif [expression]; then
7za x -p$prev_pass $eachfile
elif [expression]; then
7za x -p$prev2mon_pass $eachfile
else
mailx -s" cannot be extracted" abc@xyz.com
fi
done
}
I want to execute them in if loop if all the conditions fail it mails me with an error I am not sure how to do it please assist me with this