LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-09-2009, 02:12 PM   #1
dj_tyr
LQ Newbie
 
Registered: Oct 2009
Location: Tennessee
Distribution: Ubuntu, Fedora
Posts: 4

Rep: Reputation: 0
Read a text file and ftp files using bash w/out leaving the ftp prompt


I have a script almost working except for 1 thing & was hoping someone here could help.

What I'm trying to do is read a file that has the files that need to be FTP'd using a bash script. I have everything working except the reading of the file. It works outside of the ftp script I've wrote but once I put it in the FTP script it doesn't.

Here's the Script:

#!/bin/bash
HOST="Host_server"
FTPUSER="user"
FTPPASSWORD="*********"
FILE="ftpUpload_`date +%m-%d-%Y`"
touch "$FILE"
echo "Uploaded Files to Server on `date`:">>"$FILE"
ls>>tempfile
diff -e ftplog tempfile >> difffile
echo $HOST $FTPUSER $FTPPASSWORD
ftp -n $HOST <<-EOF
user $FTPUSER $FTPPASSWORD
cd /CVR/inspection
pwd
bin
prompt no
hash

#Here's where the problem is that I know of
!textArray[0]=""
!c=0
!while read line
do
textArray[$c]=$line
c=$(expr $c + 1)
done < difffile

!len=$(expr $c - 1)

!echo $len

!for (( i=0; i<=$len; i++));
do
put ${textArray[$i]}
done

bye
rm tempfile
rm difffile
EOF

I've been playing w/ the exclamation points to see if that could be the problem, but so far no luck.

Any help would be greatly appreciated.

Thanks
 
Old 10-09-2009, 02:23 PM   #2
ramram29
Member
 
Registered: Jul 2003
Location: Miami, Florida, USA
Distribution: Debian
Posts: 848
Blog Entries: 1

Rep: Reputation: 47
Why don't you do it with SSH instead - it allows you to use bash scripts locally or remotely.
 
Old 10-09-2009, 02:36 PM   #3
dj_tyr
LQ Newbie
 
Registered: Oct 2009
Location: Tennessee
Distribution: Ubuntu, Fedora
Posts: 4

Original Poster
Rep: Reputation: 0
We do use SSH on our end, where the script resides, but the host server is running Windows. & as for getting any assistance from the host, it would take an act of congress to get anything done.
 
Old 10-11-2009, 07:58 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,251

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025
Here's a lateral approach that I'd use. Create a dedicated txfr dir and put all files to be sent into /txfr, then

cd /txfr
mput *
 
Old 10-12-2009, 08:06 AM   #5
dj_tyr
LQ Newbie
 
Registered: Oct 2009
Location: Tennessee
Distribution: Ubuntu, Fedora
Posts: 4

Original Poster
Rep: Reputation: 0
I proposed that ideal & it was shot down. The server this will be running off of is 92% full & getting new hard drives is like pulling teeth w/out anesthesia. So hence the ideal of the script.

Thanks for the suggestion though.
 
Old 10-12-2009, 06:37 PM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,251

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025
How about http://linux.die.net/man/1/ncftpput,...et/man/1/ncftp). Basically, do all your looping outside the ftp cmd, passing the current file as a var.
http://www.unix.com/answers-frequent...transfers.html

I've got a Perl soln I wrote if you want...
 
Old 10-12-2009, 06:46 PM   #7
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by dj_tyr View Post
I have a script almost working except for 1 thing & was hoping someone here could help.

What I'm trying to do is read a file that has the files that need to be FTP'd using a bash script. I have everything working except the reading of the file. It works outside of the ftp script I've wrote but once I put it in the FTP script it doesn't.

Here's the Script:

#!/bin/bash
HOST="Host_server"
FTPUSER="user"
FTPPASSWORD="*********"
FILE="ftpUpload_`date +%m-%d-%Y`"
touch "$FILE"
echo "Uploaded Files to Server on `date`:">>"$FILE"
ls>>tempfile
diff -e ftplog tempfile >> difffile
echo $HOST $FTPUSER $FTPPASSWORD
ftp -n $HOST <<-EOF
user $FTPUSER $FTPPASSWORD
cd /CVR/inspection
pwd
bin
prompt no
hash

#Here's where the problem is that I know of
!textArray[0]=""
!c=0
!while read line
do
textArray[$c]=$line
c=$(expr $c + 1)
done < difffile

!len=$(expr $c - 1)

!echo $len

!for (( i=0; i<=$len; i++));
do
put ${textArray[$i]}
done

bye
rm tempfile
rm difffile
EOF

I've been playing w/ the exclamation points to see if that could be the problem, but so far no luck.

Any help would be greatly appreciated.

Thanks
At first glance, you need to do this with "expect". The way your script is written, it just sends things to the server whether or not the server is ready.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read a text file using a bash script Jeroen1000 Programming 8 09-30-2009 06:53 AM
Bash script to read .txt files on a remote Windows 2003 R2 server via FTP laurens Linux - Newbie 25 05-15-2009 06:01 AM
how to read text file using bash script kkpal Linux - Newbie 2 03-03-2008 11:40 AM
Read variables from a text file in Bash jakev383 Linux - General 5 12-20-2006 07:29 AM
need a perlscript to read from a text file and transfer files via ftp cccc Linux - Networking 2 02-21-2004 06:18 PM


All times are GMT -5. The time now is 06:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration