Computing.Net > Forums > Linux > FTP from within IF statement?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

FTP from within IF statement?

Reply to Message Icon

Name: dld
Date: August 28, 2008 at 02:36:59 Pacific
OS: PClinuxOS
CPU/Ram: Centrino Duo / 2G
Product: Dell XPS1210
Comment:

Dear all,
I am not sure if its possible but I want to FTP a file across to another computer - ok so that bit works - but the same script can be run from 2 different computers so I need to find out which computer I'm on first to know to send it to the other computer. Below is what I have so far but it keeps returning the old 'unexpected end of file' and I cant find the problem.Any thoughts very much appreciated.

#!/bin/bash


clear
echo "Welcome to this script"
echo " "
sleep 2

# Prompt user for current show name...
echo -n "Please enter a show name (with no spaces) \"showname\" "
read showname
echo " "

#### Pretend this is hard work..;-)
echo "Ok...working on it now "
echo " "
sleep 1

# Copy current file to 'file_showname'
cp /this/is/to/copy /this/is/new/file_$showname
sleep 1
echo "There is now a file called 'file_$showname'."
echo " "

# Overwrite the 'file_virgin file with the one we just created
cp /this/is/new/file_$showname /this/is/new/file_virgin
sleep 2
echo "'file_$showname' will be used as the file respol uses."
echo "So now when you 'respol' the system will revert "
echo "to the settings you just created."
echo " "

# Identify hostname so we know where to FTP this file to
# Create a temp file to identify controller
OUT=/the/temp/file/hosttext.txt
>$OUT
echo "$(hostname)" >> $OUT

if grep thiscomputername /the/temp/file/hosttext.txt
then
filename="/this/is/the/localfile"
hostname="theothercomputersname"
username="user"
password="pword"
ftp -inv $hostname <<EOF
quote USER $username
quote PASS $password
cd /put/it/here/
ascii
put $filename
quit
EOF
else
filename="/this/is/the/localfile"
hostname="thiscomputer"
username="user"
password="pword"
ftp -in $hostname <<EOF
quote USER $username
quote PASS $password
cd /put/it/here/
ascii
put $filename
quit
EOF
fi

sleep 2
echo " "
echo "OK..All done"
exit 0



Sponsored Link
Ads by Google

Response Number 1
Name: fberbert
Date: August 29, 2008 at 21:18:33 Pacific
Reply:

Hi,

Make sure you're not indenting the EOF string inside your if. Once the format of this forum disallow indent, I'll use ..... instead.

Look

if bla bla
then
.....ftp -inv $hostname <<EOF
.....ftp commands...
.....quit
.....EOF (wrong)
fi

And now:


if bla bla
then
.....ftp -inv $hostname <<EOF
.....ftp commands...
.....quit
EOF (right!!!)
fi

I hope this works.

---
Fabio Berbert de Paula
http://www.vivaolinux.com.br/


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: FTP from within IF statement?

ftp from windows98 to linux www.computing.net/answers/linux/ftp-from-windows98-to-linux/13751.html

ftp from clients www.computing.net/answers/linux/ftp-from-clients/23265.html

install msn messenger in linux www.computing.net/answers/linux/install-msn-messenger-in-linux/6534.html