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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ftp script error 1

Status
Not open for further replies.

try2222

Technical User
Dec 10, 2002
8
US
if i use this ftp command indented under an if clause i receive the following error:

Prova_Ftp.sh[17]: syntax error at line 22 : `<<' unmatched

The script is the following:

#!/bin/ksh
# Definizione delle Variabili

HOST=semarmx0005
USER=LRSvfo
PASSWD=LRSvfo

clear

echo &quot; Eseguire il trasferimento del package creato sull'ambiente di Produzione (10.6.92.46)??\n&quot;
echo &quot; - si&quot;
echo &quot; - no \n&quot;

read RISP

if [ &quot;$RISP&quot; != &quot;si&quot; ]
then
printf &quot;\n Trasferimento del package di rilascio interrotta!!\n\n\n&quot;
return -1
else
echo &quot;Eseguo Trasferimento del package su $HOST&quot;
ftp -v -n $HOST << EOF
user $USER $PASSWD
cd scriptroot
put production.tar
dir
bye
EOF
echo &quot;\t Trasferimento eseguito: controllare nel seguente Path: $HOME/scriptroot del server Semarmx0005 \n&quot;
fi
 

The EOF hass to be all the way to the Left. do not know why, but that is what works. Maybe sombocy can shed some light on why this has to be.
 
'else' e' inutile
visto che se $RISP non e' 'si' il programma e' terminato.
alternativa:
(
echo user $USER $PASSWD
echo cd scriptroot
echo put production.tar
echo dir
echo bye
) >ftp_cmd
ftp -v -n $HOST < ftp_cmd >ftp_output

-----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Actually you can keep the indentations. You just need to add a dash &quot;-&quot; between the &quot;<<&quot; and the &quot;EOF&quot;. The dash tells the shell to ignore leading whitespace when redirecting the following lines. Your script would look like...

[tt]
if [ &quot;$RISP&quot; != &quot;si&quot; ]
then
printf &quot;\n Trasferimento del package di rilascio interrotta!!\n\n\n&quot;
return -1
else
echo &quot;Eseguo Trasferimento del package su $HOST&quot;
ftp -v -n $HOST <<-EOF
user $USER $PASSWD
cd scriptroot
put production.tar
dir
bye
EOF

echo &quot;\t Trasferimento eseguito: controllare nel seguente Path: $HOME/scriptroot del server Semarmx0005 \n&quot;
fi
[/tt]
I've added another indent just to purty it up some.

 
Also, it's a bit of a security hole to have a username and password hard coded into a script. It's also a pain to change all your scripts if the password ever changes. A better way is to do the following...

1) Create a file called .netrc in the home directory of the person who will be running the script. Put the following line into it:
[tt]
machine semarmx005 login LRSvfo password LRSvfo
[/tt]
2) Change it so only the owner can see/use it:
[tt]
chmod 700 .netrc
[/tt]
3) Remove the &quot;user&quot; line from your ftp commands. Just doing &quot;ftp semarmx0005&quot; will start ftp and automatically log you on. You commands would look like:
[tt]
ftp -v -n $HOST <<-EOF
cd scriptroot
put production.tar
dir
bye
EOF
[/tt]

Then, if you ever need to change the username or password used to ftp to that machine, you just change it once in the .netrc file and automagically all scripts using this approach will be using the new login.
 
SamBones - I've never seen the .netrc file before - that's really useful.

I often need to ftp files from an NT machine to Unix - do you know the equivalent method on NT? (Apologies to all for asking an NT question here but it does seem easier to continue the thread here than to head off to another forum.)
 
I have a couple of ideas.

First, it may be supported on NT, but just be one of those features that's not advertised very well ([tt]ftp[/tt] help is close to nonexistant). Also, there may be a third party [tt]ftp[/tt] that supports it.

Another thing you could try is to use [tt]rcp[/tt] instead of [tt]ftp[/tt] and put an [tt].rhosts[/tt] file on the unix side. This will do the authentication on the unix side and allow the [tt]rcp[/tt] to take place without a password being supplied. Coming from NT though, it may take a lot of playing with to make it work.

Finally, go to Microsoft's web site and look up a product called Interix. It's only about $100 and gives NT a huge amount of unix functionality. This includes Korn shell, Bourne shell, C shell, cron, and a whole lot of other unix stuff. I believe the Interix ftp supports the use of .netrc. Interix even allows you to Telnet to an NT box and it looks like a unix machine. There are some differences you need to be aware of, but it really does simplify a lot of unix to NT integration issues.

Hope this helps.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top