Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AIX FTP Korn Shell Script

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi,
I have tried the AIX FTP KornShell script without using the function, and it worked, but whenItried to use function for my my script which did not work.
For example, when Iissued the ftp command :ftp -v -i 111.11.111.112 > ftp${site}_out << ENDFTP&quot; in my script,it showed the message &quot;cftp.sh[13]: 0403-057 Syntax error at line 21 : `<' is not matched.&quot;.So Ichanged the ftp command to:ftp -v -i 140.90.154.135 > ftp${site}_out \<\< ENDFTP.(Change from << to \<\<) It still did not work neither.
Thank you for any assistance.
Below is my AIX FTP Korn Shell script:
+1#! /bin/ksh
+2# File: cftp.sh
+3# FTP FUNCTIONS #
+4
+5function LAST_MAX_LINE_FILE {
+6typeset MAXLINE=60
+7#typeset MAXLINE=6000
+8tail -$MAXLINE $logfile > tempFile
+9mv tempFile $logfile
+10return 0
+11}
+12
+13function myftp {
+14typeset rhost=${1}
+15typeset remote=${2}
+16typeset line=$3
+17typeset site=${4}
+18#typeset MAXLINE=60
+19
+20
+21ftp -v -i 140.90.154.135 > ftp${site}_out << ENDFTP
+22
+23cd $remote
+24lcd /home/cindyc/ftp/get_files
+25type binary
+26
+27dir
+28mget *
+29quit
+30ENDFTP
+31
+32logfile=/home/cindyc/ftp/logs/${site}.LOG_`date +%m +%d`
+33
+34echo &quot;***************************** `date +%d` `date +%b` `date
+35+%Y` `date +%T` NOS_server Line: $line&quot; >> $logfile
+36
+37cat ftp${site}_out >> $logfile
+38
+39LAST_MAX_LINE_FILE
+40return 0
+41}+42
+43
+44# MAIN BODY OF SCRIPT #
+45MAXLINE=30
+46#MAXLINE=3000
+47
+48#find /home/cindyc/ftp/logs/ -mtime +2 -exec rm {} \;
+49
+50sbLog=/home/cindyc/ftp/logs/ftpsb.LOG_`date +%m +%d`
+51
+52# FTP NOS#
+53
+54echo &quot;`date +%D` `date +%T ` NOS ftp starting...&quot; >> $sbLog
+55
+56myftp 111.11.111.112 /test/dir 75 NOS
+57
+58echo &quot;`date +%D` `date +%T` NOS ftp completed.&quot; >> $sbLog
+59
+60# FTP FNM #
+61echo &quot;`date +%D` `date +%T` FNM ftp starting...&quot; >> $sbLog
+62
+63myftp 111.11.111.112 /test2/dir 77 FNM
+64
+65echo &quot;`date +%D` `date +%T` FNM ftp completed.&quot; >> $sbLog
+66
+67# FTP HADS #
+68echo &quot;`date +%D` `date +%T` HADS ftp starting...&quot; >> $sbLog
+69
+70myftp 111.11.111.112 /test3/dir 78 HADS
+71
+72echo &quot;`date +%D` `date +%T` HADS ftp completed.&quot; >> $sbLog
+73
+74LAST_MAX_LINE_FILE
+75
+76# c_mode_program /home/cindyc/get_files/*
+77
 
Cindy,

What is the &quot;<<&quot; supposed to be doing?

I know that &quot;>>&quot; appends to a file, that &quot;>&quot; overwrites a file, and the &quot;<&quot; pulls from a file. I haven't seen the &quot;<<&quot; before ....


Thank you,
-MissVick [sig][/sig]
 
<grin> the << is one of my favorite things

it's called the &quot;here document&quot; which help much - but it's dead easy to use

say you have a command which takes input from stdin and does something -- say also that it's not convenient to pipe something from another command.

A trivial example: &quot;Create a file with two lines, &quot;Mike Lacey&quot; on the first line and &quot;Michael Lacey&quot; on the second. You can use the [tt]cat[/tt] command and [tt]<<[/tt] to do this quite neatly in script.
[tt]
cat <<EOF
Mike Lacey
Michael Lacey
EOF
[/tt]

You could read this as: Run the cat command and feed it's stdin with everything following this line up to the line containing the characters [tt]EOF[/tt]

Doesn't have to be [tt]EOF[/tt], I would normally write:
[tt]
cat <<!
Mike Lacey
Michael Lacey
!
[/tt]

And that would do exactly the same thing. [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>[/sig]
 
Mike,

Thanks! :) That clarifies what she's trying to do in the script, but not sure why, then, she's getting the '<' is not matched.

I wrote a similar script with just the

ftp -v hostname >lookatme <<!
cd /usr
dir
quit
!

and did not have a problem. I also introduced $site into the ftp line without issues. Perhaps it is something above line 21 that is at issue?
I did notice that the closing &quot;}&quot; for myftp is listed on line 41/42:

+41}+42

and wonder if that is just how it copied into these notes or if there is something going on with the spacing in the script.

Anyway, thank you again Mike for clarifying the &quot;<<&quot; for me. Always nice to learn something new like that.

-MissVick [sig][/sig]
 
Hi Mike,

I have tried the AIX heredoc(<<) KornShell script in the main script, and it worked, but when I tried to use heredoc in the function, it did not work.

Thank you for any assistance that you may provide.

ctest[5]: 0403-057 Syntax error at line 6 : `<' is not matched.

+1 #! /usr/bin/ksh
+2
+3 # File: ctest
+4
+5 function printEnd {
+6 cat << EOF
+7 jenny
+8 chong
+9 EOF
+10 return 0
+11 }
+12
+13 ## MAIN BODY OF SCRIPT ##
+14 printEnd
+15 exit 0

 
Cindy,

If you want to leave whitespace before the EOF (or ! or whatever you're using to complete the heredocuthingy) you have to specify it like this
[tt]
ftp aslkjdakjs [red]<<-![/red]
kjashdkj
kasdkjas
!
[/tt]

You need to say [tt]<<-![/tt] instead of just [tt]<<![/tt]

Mike
michael.j.lacey@ntlworld.com
 
(1) I have tried some &quot;ftp&quot; on AIX, before, and in my experience, &quot;ftp&quot; acts like a &quot;copy&quot; command, in that it &quot;sends&quot; a NAMED-file from one machine to another.

So, you need to HAVE a NAMED-file FIRST, in order to be able to &quot;ftp&quot; it!

(2) I am a little-bit familiar with a &quot;here&quot; document in Kornshell, and (it seems to me) one would, ordinarily &quot;write&quot; the contents of the &quot;here&quot; document to some NAMED-file, THEN, in a following job-step (in the &quot;main&quot; script?), you can &quot;ftp&quot; that new Named-file (which NOW has the contents of the &quot;here&quot; document) to the &quot;other machine&quot;, or site.

Something like:

#!/bin/ksh
# Program: &quot;ftp_script.ksh&quot;
# --------------------------------------
cat > file_with_stuff_to_ftp.whatever << MARKER
Line-1
This is line-2
3rd.-line

line-5
MARKER
# -------------------------------------
echo &quot;-------------------------------&quot;
cat file_with_stuff_to_ftp.whatever
echo &quot;-------------------------------&quot;
ftp <some-other-machine-or-site>
<logon-with-your-password>
<put file_with_stuff_to_ftp.whatever> <space\s> <file_with_stuff_to_ftp.whatever>
<enter>
<quit>
# End-of-Script
===========================================
Note-1: Everything between &quot;ftp&quot; and <# End-of-Script> is &quot;interactive&quot; which means it must be entered by the user on the keyboard.

Note-2: everything starting between &quot;<put..&quot; and &quot;<quit>&quot; is all ONE-LINE
==========================================
(3) Also, you might try &quot;rcp&quot; (remote copy
command), rather than &quot;ftp&quot;, at the point where you invoke &quot;ftp&quot;. The &quot;rcp&quot; command would work much like the &quot;cp&quot; command, but would NOT have to be &quot;interactive&quot;..except maybe for a &quot;logon&quot;, and a password.

You wouldn't need the &quot;put&quot;-part, needed to be entered ineractively with the ftp command.
(That, instead, would be a part of the &quot;rcp&quot; command-line.)

(4) I think the 'rcp&quot; command has to be &quot;setup&quot; via a &quot;rhosts&quot; file, before it can succeed, but then it would work like:

rcp <file2send> <user-id>@<some-other-machine>:<path> <file2send> # All-one-line

(5)I think you MUST have a &quot;.rhosts&quot; file in the <some-other-machine>, for &quot;rcp to work.

(6) Also, of course, you have to have &quot;write&quot; permission and leftover disk space, or quota, on the <some-other-machine>

(7) Also, you might try &quot;scp&quot; (secure-copy), if needed instead of &quot;rcp&quot;.
============================================
(8) An excellent (new, I think) book that covers some of the &quot;ftp&quot;, &quot;rcp&quot;, and 'scp&quot; stuff is:

&quot;Your Unix - The Ultimate Guide&quot;, by Sumitabha Das, by McGraw Hill, P-335-338.

It also covers most other Unix stuff in an
EXCELLENT way (I think).

End-of-memo: Best to you..
from ernieah.
 
I suppose you haven't login validation otherwise you should run the script like:
ftp -n host << EOF
user user_name user_passwd
cd download_remote_directory
lcd download_local_directory
prompt
mget files*
quit
quit
quit
<<EOF

I use more quit just to exit from ftp in any case
 
from original post...
looks like a space in there on line 21: << ENDFTP
take that out: <<ENDFTP

IBM Certified -- AIX 4.3 Obfuscation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top