loop logic inside of an inline redirect?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting loop logic inside of an inline redirect?
# 1  
Old 06-12-2009
loop logic inside of an inline redirect?

i need to log the feedback from the ftp server as i'm performing some deletes.
the only way i know of to do this is with the inline redirect << EOF
... but from there to the closing EOF, it's like i'm at the ftp command prompt, so I don't know how to have ksh script logic in there
I have an array of file names to delete and am looping them.... which requires reconnecting for every file. Smilie

Is there a way to loop the file list and issue a delete for each, while logging the feedback... without re-connecting for each file?
connect once, delete many, & capture it all.

here is the function in the korn shell script...

function removeFiles {
for aFile in ${MFfilesToDelete[*]}
do
ftp -ivtn ${MF_IP} >> "${FTPLOG}.$1" >&1 <<EOF
user ${MF_USER} ${MF_PASS}
rm ${aFile}
bye
EOF
done
}


-----Post Update-----
# 2  
Old 06-12-2009
Those redirects are called 'here documents' in unix. Put the filename array into a flat file
Code:
echo "
user ${MF_USER} ${MF_PASS}
$(awk '{print "rm", $0" }' filenames_file)
bye
" | /usr/bin/ftp -ivt ${MF_IP} > "${FTPLOG}.$1"

# 3  
Old 06-12-2009
something like this:
Code:
#!/bin/ksh

function removeFiles {
ftp -ivtn ${MF_IP} >> "${FTPLOG}.$1" >&1 <<EOF
user ${MF_USER} ${MF_PASS}
$(
for aFile in ${MFfilesToDelete[*]}
do
   echo "rm ${aFile}"
done
)
bye
EOF
}

# 4  
Old 06-12-2009
so we can use $() within a here document to execute something

Sweet!
Thank you both. that's working
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to redirect the output of a command inside ftp block?

hi, i am using ftp to get files from remote server. inside the ftp i want to us ls -ltr command and send the output of it to a file. ftp -n remote_server <<_FTP quote USER username quote PASS password prompt noprompt pwd ls -ltr get s1.txt bye _FTP i... (4 Replies)
Discussion started by: Little
4 Replies

2. Shell Programming and Scripting

while loop logic

Hi, Here I am trying to query database and check a value, if the value not matches then I wants to re-query the database.Once the value matches, I want to email the reqidstatus_log.txt file. Database query produces a file reqidstatus_log.txt which contains result. But the query not working as... (3 Replies)
Discussion started by: rajsp217
3 Replies

3. Shell Programming and Scripting

Inline searc and replace inside file

Hello, I have a text file that i want to redirect into a new file , searching and replacing certain string during the opertaion. This should be done using shell script , so it should not be interactive. The script should get four parameters : source file target file source string target... (1 Reply)
Discussion started by: yoavbe
1 Replies

4. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

5. UNIX for Advanced & Expert Users

inline redirect stdin

Hi: I have the next script on ksh #!/usr/bin/ksh cd $FUENTES qdesign <<-! \$/opt/cognos/ph843e/bin/qtp <<-! \$/opt/cognos/ph843e/bin/quiz <<-! ! ! ! This script is very simple, i want to nest three process quiz into qtp, and this into qdesign. When I run it , i receive the next... (2 Replies)
Discussion started by: ct2marer
2 Replies

6. Shell Programming and Scripting

inline redirect stdin

Hi: I have the next script on ksh #!/usr/bin/ksh cd $FUENTES qdesign <<-! \$/opt/cognos/ph843e/bin/qtp <<-! \$/opt/cognos/ph843e/bin/quiz <<-! ! ! ! This script is very simple, i want to nest three process quiz into qtp, and this into qdesign. When I run it , i receive the... (5 Replies)
Discussion started by: ct2marer
5 Replies

7. Shell Programming and Scripting

While Loop Logic

I would need to with making while loop logic working in shell program when I am new into the shell programing 1) I would need to try to get the file from the remote side ----need to try 15 mins apart for 4 times and terminate the program if file is not available.... I would need to know how I... (4 Replies)
Discussion started by: sambakamba
4 Replies

8. Programming

Inline function inside Classes

#include <iostream> using namespace std; class A { public: int Getvalue() { return i;} private: int i; }; int main() {} The above code compiles properly in g++ or in any other C++ compiler. BUT, the variable 'i' is used (in 'return i' statement) before it is... (1 Reply)
Discussion started by: deepthi.s
1 Replies

9. Shell Programming and Scripting

[BASH] redirect standard error and use it inside

Hi all, Maybe my question is too simple but till now i couldn't figure about a solution :( I have a bash script scheduled in cron: <cron time parameters> my_script.sh > result.log 2>&1 By this way i can have standard output and standard error in my result.log file Now i want my script... (2 Replies)
Discussion started by: Pescator
2 Replies
Login or Register to Ask a Question