Sponsored Content
Top Forums Shell Programming and Scripting Adding a Fileinput loop to exsiting script. Post 302346892 by netmad0 on Monday 24th of August 2009 10:37:34 AM
Old 08-24-2009
Question Adding a Fileinput loop to exsiting script.

Smilie I'm very confused on what I need to do. I've looked at if, while, but I can't seem to visualize where in my current script to put the commands.
I'm looking to read a directory /ERD/iface/data/ocom/citi/idd because there will be multible files, but I need to process them one at a time. The Process is copy the file, encrypt the file, send the file, delete the file. How do I loop this? Thank you VERY much.

Code:
# Set local variables.
SN=pgp_cfs_idd_encrypt
ENCRYPT=enc_sig_CFS_IDD
SEND=eapsend_cfs_idd_prod
MSGDIR=/home/pgp/messages/CFS
SAPDIRIN=/ERD/iface/data/ocom/citi/idd
DIRDOUT=/home/pgp/CFSUSA/outgoing_files/decrypted
DIREOUT=/home/pgp/CFSUSA/outgoing_files/encrypted
FILEIN=decrypt*  (all files are named decrypt_test_move_YYYYMMDD_HHMMSS)
FILEOUT=test_cfs_citiidd
FAILSCRIPT=Nothing

# ONLY send mail and first cp lines need to change below this line. #
# Error_Successmsg routine function.
Operator_Error_Msg()
{
mail -s " $SN failed in $FAILSCRIPT " mdurette@*****.com </home/pgp/CFSUSA/notes/failcfs
}
Operator_Success_Msg()
{
echo " $SUCCESSMSG was successful "
}
START=0
# Change to the $SAPDIRIN directory and copy the file from SAP to PGP
if [ $START = 0 ]; then
cd $SAPDIRIN
cp $FILEIN /home/pgp/CFSUSA/outgoing_files/decrypted/$FILEOUT > $MSGDIR/$SN 2>&1
COPY=$?
echo "The copy from SAP to PGP RC= $COPY" >> $MSGDIR/$SN 2>&1
SUCCESSMSG=start
Operator_Success_Msg
else
FAILSCRIPT=start
exit $START
fi
# If the copy was successful, encrypt the file.
if [ $COPY = 0 ]; then
/home/pgp/scripts/$ENCRYPT \
$FILEIN \
$FILEOUT > $MSGDIR/$SN 2>&1
PGP=$?
echo "The encrypting of the decrypt file RC= $PGP" >> $MSGDIR/$SN 2>&1
SUCCESSMSG=step1_copy
Operator_Success_Msg
else
FAILSCRIPT=step1_copy
Operator_Error_Msg
exit $COPY
fi
# If encryption was successful, test if EDI server is up.
if [ $PGP = 0 ]; then
/etc/ping -c 1 ecprod >> $MSGDIR/$SN 2>&1
PING=$?
echo "The pinging of ECPROD server RC= $PING" >> $MSGDIR/$SN 2>&1
SUCCESSMSG=step2_encrypt
Operator_Success_Msg
else
FAILSCRIPT=step2_encrypt
Operator_Error_Msg
exit $PGP
fi
# If encryption and ping was successful, send the file out.
if [ $PING = 0 ]; then
/usr/local/bin/$SEND >> $MSGDIR/$SN 2>&1
SEND=$?
echo "The encrypted file has been sent RC= $SEND" >> $MSGDIR/$SN 2>&1
SUCCESSMSG=step3_ping
Operator_Success_Msg
mail -s "Script Citibank IDD File System" -c "mdurette@*****.com" \
ops@*****.com</home/pgp/CFSUSA/notes/CFSIDDgood
else
FAILSCRIPT=step3_ping
Operator_Error_Msg
exit $PING
fi
# If the send was successful, delete the SAP file, decrypted file encrypted file.
if [ $SEND = 0 ]; then
cd $DIRDOUT
rm -f $FILEIN >> $MSGDIR/$SN 2>&1
REMV2=$?
cd $DIREOUT
rm -f $FILEOUT.pgp >> $MSGDIR/$SN 2>&1
REMV3=$?
echo "The Decrypted RC= $REMV2 file and the Encrypted RC= $REMV3 file have been deleted. " >> $MSGDIR/$SN 2>&1
SUCCESSMSG=step4_send
Operator_Success_Msg
else
FAILSCRIPT=step4_send
Operator_Error_Msg
exit $SEND
fi
# End of script.


Last edited by vgersh99; 08-24-2009 at 11:38 AM.. Reason: code tags, PLEASE!
 

10 More Discussions You Might Find Interesting

1. Programming

adding variables for, for loop

I have a structure which contains n number of elements. For example: stFruits : apple, grapes, strawberry, pear, kiwi, melon, papaya, mango, orange, sweetlime ..... etc Now i have to write a for loop as follows: int i; int j; j=stFruits.apple+stFruits.grapes+stFruits.pear+.... and so... (3 Replies)
Discussion started by: jazz
3 Replies

2. Shell Programming and Scripting

adding values with a loop

Hi there, I am checking disk spaced used on a box # df -k | grep dsk | awk {'print $3'} 2055463 20165785 18310202 32274406 I want to somehow add them up but am no quite sure how to do this in a loop. ...i.e for n in 'df -k | grep dsk | awk {'print $3}' do <some adding... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

3. Shell Programming and Scripting

doing a for loop adding up the results

Hi there If I run a 'swap -l' on my solaris box, i get swapfile dev swaplo blocks free /dev/dsk/c1t0d0s1 54,65 8 67119560 65655144 /dev/dsk/c1t0d0s2 54,65 8 33119522 32655122 I wanted to run a for loop adding up the totals of each column 4 , excluding the... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

4. Shell Programming and Scripting

Adding string variable dynamically in for loop

Hi, I need to generate the text name dynamically in for loop, ex, VAR_COPY_FILE1= file path 1 VAR_COPY_FILE2= file path 2 VAR_COPY_FILE3= file path 3 for i in 1 2 3 do if then "do some process here" fi done (3 Replies)
Discussion started by: msubash26
3 Replies

5. Shell Programming and Scripting

adding counter to a variable while moving in a loop

The scenario is like this : I need to read records from a file one by one and increment counter1, if a certain field matches with a number say "40"..the script should increment the counter2 and also extract a corresponding field from the same line and adding them one by one and redirecting the the... (5 Replies)
Discussion started by: mady135
5 Replies

6. Shell Programming and Scripting

Help needed: Adding columns in csv file in loop

Hi Everyone: My shell script creates multiple csv files (~30) in for loop. I want to compile (or merge) 3rd column from each (all) of these files to another file (in loop). Please help. Thanks. (3 Replies)
Discussion started by: smap007
3 Replies

7. Shell Programming and Scripting

Adding a while loop to my script

I have a script below that goes to the given directory and plays the newest powerpoint presentation via powerpoint viewer and wine. So far it works perfectly but now Id like to add a while statement to essentially run find /ticker/powerpointshare -mmin -1 -type f -iname "*.ppt" and if it finds a... (9 Replies)
Discussion started by: binary-ninja
9 Replies

8. Shell Programming and Scripting

Bash: adding commas in for loop

Dear Experts I think this is possibly the easiest thing. but I am not able to solve: I need comma to be added to end of each line echo'd. But does not want it to be added to last line. I have a script which does some data analysis and creates a command as in below code snippet for... (4 Replies)
Discussion started by: chakrapani
4 Replies

9. Shell Programming and Scripting

adding one more column in a loop

data1 1 0.01 3 5 1 0.6 2 1 data2 2 0.02 3 5 2 0.3 2 1 data3 3 0.01 3 5 3 0.01 2 1 output 1 0.01 data1 2 0.02 data2 3 0.01 data3 3 0.01 data3 I want to print 1st, 2nd column and the filename when second column is less than 5. (3 Replies)
Discussion started by: johnkim0806
3 Replies

10. Shell Programming and Scripting

Help on Adding one counter loop at the end of each line in a file

Hello All, I have file a.txt I want to add a counter loop at the end of each line in a file ill explain: i have a site h**p://test.test=Elite#1 i want to add a a counter to the number at the end of the file, that it will be like this urlLink//test.test=Elite#1 urlLink//test.test=Elite#2... (3 Replies)
Discussion started by: nexsus
3 Replies
All times are GMT -4. The time now is 11:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy