Multiple exec command s in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple exec command s in a script
# 1  
Old 06-29-2003
Question Multiple exec command s in a script

Hi everyone,

I've been racking my brains for ages on this and need your help/advice.

I am writing a script that is reading in file to process and putting them into a temporary file. The loop starts and the script gets the first file name, does what i needs to do (copy it) and then returns to the top of the loop for the next file. Due to the nature of the system While inside the read line loop I have to get the next sequence number from another file which is generated by an export of an oracle table. This is then appeneded to the filename.
The problem here is that as soon as I try and read in the sequence number any subsequent files are blank. The code im using is

ifdtime=`date +%d%m%y%H%M` ; export ifdtime
LOG_FILE="/test/ohms/jobs/log/if.log" ; export LOG_FILE
LOGDIR="/test/ohms/jobs/log" ; export LOG_DIR
LOCKFILE=/tmp/KSJOBLOCK_${ORACLE_SID} ; export LOCKFILE
FILESIN=/servintftest/input/orders ; export FILESIN
runtime=`date "+%H:%M"`
rundate=`date "+%d/%m/%y"`
>$LOG_FILE

## Functions - the 2 reads are becuase oracle generates a blank line at start

get_seqno ()
{
exec < /home/interfac/scripts/seq.num;
read mark
read mark
seqno=$mark
echo $seqno
}

## Check to see if any files exist if not then abort the interface

if [ `ls -1 /servintftest/input/orders/ORDER* | wc -l` = 0 ]
then
echo "ERROR: No Files Received"
echo "${ifdtime} : ERROR: No Files Received" >>$LOG_FILE
exit
fi

## Files must exist if we got this far so read all filenames into a temp file

rm $LOGDIR/ohms_files
>$LOGDIR/ohms_files
ls -1 $FILESIN/ORDER*|cut -c28- >> $LOGDIR/ohms_files

## Now that we have the list lets process the files one by one

exec < $LOGDIR/ohms_files;
while read line
do
set - $line

## Get the last sequence number from the external system table

get_seqno

## Now copy the file but change the filename to ohmsjobs and seq no

echo "Copying file..."
cp -p $FILESIN/$1 /test/ohms/input/ohmsjobs.${seqno}
#cp -p /test/ohms/input/$1 /test/ohms/jobs/backup/ohmsjobs.${seqno}.${ifdtime}
if [ -f /test/ohms/input/ohmsjobs.${seqno} ]
then
echo "${ifdtime} : OHMS file copied $1 renamed to ohmsjobs.$seqno" >> $LOG_FILE
echo "${ifdtime} : OHMS file copied $1 renamed to ohmsjobs.$seqno"
sleep 5
#rm $FILESIN/$1fi


## Interface must have completed and a backup copy has been taken so delete

#rm /test/ohms/input/$1

done

Any help you can give would be appreciated

Regards,
Mark
# 2  
Old 06-29-2003
Try changing
exec < $LOGDIR/ohms_files;
while read line

to this
exec 5< $LOGDIR/ohms_files;
while read -u5 line

If that doesn't work, give a few details, like: what system? what os? what shell?
# 3  
Old 06-29-2003
A few things...

if [ -f /test/ohms/input/ohmsjobs.${seqno} ]
There's no closing fi statement (it's commented out).

Since the get_seqno() subroutine is pulling seq.num each time, isn't the value of $seqno going to be the same with each iteration of the loop?

When you say that subsequent files are blank, do you mean that all the files in the ohmsjobs.${seqno} format that you'd expect to be created are created, but they're all empty?

Oh, and just a side note, you can eliminate the second echo command by using tee.. Smilie

echo "${ifdtime} : OHMS file copied $1 renamed to ohmsjobs.$seqno" | tee -a $LOG_FILE
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Programming

Script to monitor progress of find/exec command

hi all, i want to monitor the progress of a find and exec command, this is the code i use - find . -type f -exec md5sum {} \; >> /md5sums/file.txt this command works and produces a text file with all the md5sums but while running it doesnt show the progress is there anyway i can do this... (4 Replies)
Discussion started by: robertkwild
4 Replies

3. Programming

Bash script - find command with delete and exec

hi all, i have devised a script that starts in /restored/ and in there, there are a lot of sub folders called peoples names and in the sub folders are files/folders and it deletes the data in the sub folders BUT not the sub folder itself and it should then touch a file in all the sub folders... (3 Replies)
Discussion started by: robertkwild
3 Replies

4. Shell Programming and Scripting

Use of exec command in a script

Guru's, I want to make a use of "exec" command in my script and want to check return code of executing script, but as you know exec command will terminate current processID and comeout and will trigger new one, i am unable to check return code of script and not able to run a scrpit after exec. ... (2 Replies)
Discussion started by: pawar.atul28
2 Replies

5. UNIX for Dummies Questions & Answers

Using find -exec with multiple commands :(-

Hi all, Am wanting to do a ls -l of the files and do a cat of it at the same time, ideally, I am hoping that the following work but obvisouly it is not working to what I am wanting it to ... hu hu hu :wall: find . -name "BACKUP_TIMESTAMP.log" -exec "ls -l basename {} ; cat {}" \; ... (1 Reply)
Discussion started by: newbie_01
1 Replies

6. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

7. Shell Programming and Scripting

exec perl in expect script yields "invalid command"

I'm trying to execute something like this: exec perl -i -pe 's/\015/\012/g' '${file}' in my expect script and I get: error "invalid command name \"perl\". however, if I run perl -i -pe 's/\015/\012/g' "/Users/Shared/menu-items.txt" directly in my terminal, it runs fine. I'm an... (4 Replies)
Discussion started by: dpouliot
4 Replies

8. Shell Programming and Scripting

find command to use multiple -exec options

Hello All, Is there a way to make exec do a couple of operations on a single input from find? For example, find . -type d -exec ls -l "{}" ";" I would like to give the result of each "ls -l" in the above to a wc. Is that possible? I want to ls -l | wc -l inside exec. How do I... (1 Reply)
Discussion started by: prasanna1157
1 Replies

9. Shell Programming and Scripting

Help! Paste Multiple SQL output result to exec command

Hi, I want to write the shell script to change multple file name (the file name is get from DB) e.g. cp db1.txt file1_new.txt cp db2.txt file2_new.txt cp db3.txt file3_new.txt I have write the script like this: VAR=`sqlplus -s $LOGON @<<ENDOFTEXT set termout off ... (0 Replies)
Discussion started by: jackyntk
0 Replies

10. Shell Programming and Scripting

exec a build command (adduser) in a script

Hi, With a awk script i create a "adduser line" $ cat /tmp/tmp.ldif | awk -f ldif2adduser.awk adduser --uid 1002 --gid 1000 --gecos "ROUSSIN Guy" --home /homeL/guy --shell /bin/bash --disabled-password guy If i cut and paste this line, all is fine. But in a shell script i get errors : ... (2 Replies)
Discussion started by: guyr
2 Replies
Login or Register to Ask a Question