UNIX ZIP WITH PASSWORD in CSH

I like to email 10000   .csv files to 10000 email address using zipping and password. Password will be generated randomly. ZIP file and Password needs to be stored local drive before sending email. I did it using ZIP command but ZIP is not supporting in CSH, as I am working in CSH. If there is any way(command) so that I can do same thing in UNIX CSH. Thanks ~ Nazrul
My Code is:
BCPUSERID=$SIFFILEDIR/$USERID
BCPUSERIDEMAIL=$SIFFILEDIR/$USERIDEMAIL
BCPUSERMESSAGE=$SIFFILEDIR/$USERMESSAGE
BCPFILE=$SIFFILEDIR/$SIFNAME
PASSWORDFILE=${SIFFILEDIR}/passwords.csv
echo "The current date: " >> $PASSWORDFILE
while read userid
   do
   NEWFILE=${SIFFILEDIR}/${userid}.csv
   ZIPFILE=${SIFFILEDIR}/${userid}.zip
   PASSWORD=$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 8)
   echo $userid,$PASSWORD >> $PASSWORDFILE
   echo "AccountCode,IECode,UserID,TotalFeeAmount,TotalTaxAmount,IEPayoutAmount" >> $NEWFILE
   grep "${userid}" $BCPFILE >> "$NEWFILE"
   EMAIL=`grep "${userid}" $BCPUSERIDEMAIL | cut -d"," -f2`
   zip -P $PASSWORD $ZIPFILE $NEWFILE
   uuencode ${ZIPFILE} ${ZIPFILE} | mailx -s "Report" ${EMAIL}
done < "$BCPUSERID"
Nazrul10Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bryan ButlerCommented:
Zip should work fine.  What error are you getting?  According to the man page I looked at, -e is the password option.  Does your man page say -P?
0
arnoldCommented:
If this is a script, you are not limited to csh.
Whatever you put on the first line will be the environment in which the script is executed as long as it is not explicitly run by csh script.
#!/bin/sh
you may need to use setenv to set the variables if you are using csh.
What is the error that you get?
0
AmolCommented:
you have to enter #!/bin/csh at the start of the script ...
0
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Nazrul10Author Commented:
I used #!/bin/csh at the start of the script and shows "Variable syntax Error"
I used #!/bin/sh at the start of the script and shows "zip: not found"
Yeap, man page say -P    for password
My complete code:
#!/bin/sh
#set -x
if [ $# -ne 0 ]; then
    echo >&2 "`date '+%D %T'` : Usage: fc_hist_billing_curr_year_email.sh YYYYMMDDHHMMSS"
    exit 1
fi
. $HOME/env/fc_env.sh
. $HOME/env/fc_dbuser.sh
TIMESTAMP=$1
FC_LOG_FILE=$FC_LOG/fc_hist_billing_curr_year_email_${TIMESTAMP}.log
echo "\n\nStart fc_hist_billing_curr_year_email.sh at `date '+%b %d %Y %T'`\n" >> $FC_LOG_FILE
CLIENT=FC
SIFNAME=fc_hist_billing_curr_year.txt
USERID=useridtemp1.txt
USERIDEMAIL=useridemailtemp1.txt
USERMESSAGE=message.txt
SIFFILEDIR=$FC_DATA/output_hist_billing_curr_year
if [ ! -d "$SIFFILEDIR" ]; then
     mkdir $SIFFILEDIR
fi
BCPUSERID=$SIFFILEDIR/$USERID
BCPUSERIDEMAIL=$SIFFILEDIR/$USERIDEMAIL
BCPUSERMESSAGE=$SIFFILEDIR/$USERMESSAGE
BCPFILE=$SIFFILEDIR/$SIFNAME
while read userid
   do
   NEWFILE=${SIFFILEDIR}/${userid}.csv
   ZIPFILE=${SIFFILEDIR}/${userid}.zip  
   echo "AccountCode,IECode,UserID,TotalFeeAmount,TotalTaxAmount,IEPayoutAmount" >> $NEWFILE
   grep "${userid}" $BCPFILE >> "$NEWFILE"
   EMAIL=`grep "${userid}" $BCPUSERIDEMAIL | cut -d"," -f2`
  zip -P abcd $ZIPFILE $NEWFILE
   uuencode ${ZIPFILE} ${ZIPFILE} | mailx -s "Report" ${EMAIL}
done < "$BCPUSERID"
ret1=$?
if [ $ret1 -ne 0 ]; then
     echo "\nfc_hist_billing_curr_year_email.sh failed at bcpout $BCPFILE.\n" >> $FC_LOG_FILE
     echo >&2 "\n\nfc_hist_billing_curr_year_email.sh failed at bcpout $BCPFILE. Please check $FC_LOG_FILE for details.\n"
     exit 1
fi
echo " bcpout $BCPFILE ended at `date '+%b %d %Y %T'` with return status $ret1\n" >> $FC_LOG_FILE
echo "\n`date '+%D %T'` : bcpout $BCPFILE completed with return status $ret1"
exit 0
0
arnoldCommented:
replace zip with /usr/bin/zip and see if that fixes the issue within sh.

What are you setting in:
$HOME/env/fc_env.sh
. $HOME/env/fc_dbuser.sh

Are you altering the PATH variable such that it does not include /usr/bin which is where zip can be found??
export PATH=/usr/bin:$PATH
Should fix the issue.
0
Nazrul10Author Commented:
I didn't see any zip command in /usr/bin/
So it doesn't make sence to me, it will work without zip in /usr/bin/zip location. I didn't see gzip either in /usr/bin/zip
I tryed    export PATH=/usr/bin:$PATH   , not work, as zip is not there.
I am not altering the path variable into following. These are the path of all .txt/.csv/.zip/.log file
. $HOME/env/fc_env.sh
. $HOME/env/fc_dbuser.sh
Thanks
0
Nazrul10Author Commented:
Hello is there is any command except zip / gzip for zipping .csv files with a password in csh
Thanks~Nazrul
0
arnoldCommented:
The problem you are having is less to do with the shell (Sh, bash, CSH, tcsh, zsh, ksh) and more to do with the path to the file.  If you use an explicit path i.e. /usr/bin/zip you should not have an issue unless the way the system you access is setup prevents it i.e. chrooted environement which is limiting to the commands made available by the systems administrator.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.