LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-13-2009, 07:02 AM   #16
laurens
Member
 
Registered: Mar 2009
Posts: 65

Original Poster
Rep: Reputation: 15

Thanks David,
Does this create an array? How can I get the values?
To answer your questing, in fact, there is no need to create an array. The IP shouldn't be reused or something. It's just a matter the IP addresses should be compared with the IP_folderlist.txt files.
 
Old 05-13-2009, 10:09 AM   #17
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
I'm pretty new to arrays myself, but for information about them (along with just about everything else), check out the Advanced Bash Scripting Guide. There are several ways to initiate and populate array entries, one of which is to use a loop like the one in your first post. Individual array entries can be used very much like variables, only with index number attached to them. 'echo "${ARRAY[2]}"' will show you the contents of the 3rd array entry (the numbers start at 0).

But arrays are only really needed when you want to be able to control and manipulate individual entries in your list. Since you just want to run the same commands on each line in turn, a simple "for" loop is really all you need. For example, to ping each of the addresses in the "iplist" variable:

Code:
for LINE in $iplist; do
     
     echo "Pinging IP address: $LINE"
     ping -c 1 $LINE

done
Learn more about loops here.

So whatever you want to do to each address will go inside a loop like this. Now please explain in more detail what you want. It looks to me like you want to search for each IP address in the filenames in the current working directory, am I right? A simple find command with the $LINE variable as the search string will do that. But what do you want it to do if it finds, or if it doesn't find, a file with that name?
 
Old 05-13-2009, 11:24 AM   #18
laurens
Member
 
Registered: Mar 2009
Posts: 65

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by David the H. View Post
I'm pretty new to arrays myself, but for information about them (along with just about everything else), check out the Advanced Bash Scripting Guide. There are several ways to initiate and populate array entries, one of which is to use a loop like the one in your first post. Individual array entries can be used very much like variables, only with index number attached to them. 'echo "${ARRAY[2]}"' will show you the contents of the 3rd array entry (the numbers start at 0).

But arrays are only really needed when you want to be able to control and manipulate individual entries in your list. Since you just want to run the same commands on each line in turn, a simple "for" loop is really all you need. For example, to ping each of the addresses in the "iplist" variable:

Code:
for LINE in $iplist; do
     
     echo "Pinging IP address: $LINE"
     ping -c 1 $LINE

done
Learn more about loops here.

So whatever you want to do to each address will go inside a loop like this. Now please explain in more detail what you want. It looks to me like you want to search for each IP address in the filenames in the current working directory, am I right? A simple find command with the $LINE variable as the search string will do that. But what do you want it to do if it finds, or if it doesn't find, a file with that name?
Thanks! I wasn't aware of the great functionality of your code. When I execute it, it gets all the IP's (already a nice step forward) and PINGs them. With success. Will come in handy if I'll have to check if the servers are still 'alive'.

So that was step1, thanks for that. Yes, the scenario you gave there is quite correct. As you see the ftpservers.txt file contains IP addresses, usernames and passwords. Now, a function should scan if there are files with a matching IP_folderlist in the current directory.
The folders have to be copied via FTP. But in the first place I would suggest to echo the folders.

I give an example of how the output could look like:
Code:
212.124.56.75
docshop.xx.be\files
extranetdocshop.xx.be\files
fleet.xx.be\doccshop\files
212.124.56.76
-nothing-
212.124.56.101
project.xx.be\html\upload
project.xx.be\html\attachment
212.124.56.113
-nothing-

...etc...
Please check the printscreen I added.

Later on a ftp connection should be made with the servers via the username and password provided in the ftpservers.txt

Thanks in advance !

Last edited by laurens; 05-14-2009 at 08:21 AM.
 
Old 05-13-2009, 01:01 PM   #19
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by laurens View Post

So that was step1, thanks for that. Yes, the scenario you gave there is quite correct. As you see the ftpservers.txt file contains IP addresses, usernames and passwords. Now, a function should scan if there are files with a matching IP_folderlist in the current directory.
The folders have to be copied via FTP. But in the first place I would suggest to echo the folders.

So why don't you just replace the ping with
that check in his loop?

Code:
for LINE in $iplist; do
  echo "checking for file per IP address: $LINE"
  if [ -e ${LINE}_folderlist ]; then
    echo "Found ${LINE}_folderlist"
  else
    echo "No folderlist for ${LINE}"
  fi
done

Cheers,
Tink
 
Old 05-14-2009, 03:46 AM   #20
laurens
Member
 
Registered: Mar 2009
Posts: 65

Original Poster
Rep: Reputation: 15
Thanks for the input Tinkster, though I get 'No folderlist' for every checked IP address. Also those for which there exists a _folderlist.txt
I tried with both '_folderlist' (as you gave me) and '_folderlist.txt'
Are you sure it's checking the currect directory?

Code:
checking for file per IP address: 80.xx.xx.76
No folderlist for 80.xx.xx.76
checking for file per IP address: 212.xx.xx.52
No folderlist for 212.xx.xx.52
...etc...
Thanks in advance

Last edited by laurens; 05-14-2009 at 05:10 AM.
 
Old 05-14-2009, 05:49 AM   #21
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by laurens View Post
Thanks for the input Tinkster, though I get 'No folderlist' for every checked IP address. Also those for which there exists a _folderlist.txt
I tried with both '_folderlist' (as you gave me) and '_folderlist.txt'
Are you sure it's checking the currect directory?

Code:
checking for file per IP address: 80.xx.xx.76
No folderlist for 80.xx.xx.76
checking for file per IP address: 212.xx.xx.52
No folderlist for 212.xx.xx.52
...etc...
Thanks in advance
Depends on how you define "currect" (a combination of current
and correct?), and how/from where the script is being invoked?
You could - for trouble-shooting purposes - echo out the
$PWD and ${LINE}_folderlist before the test.


Cheers,
Tink
 
Old 05-14-2009, 10:49 AM   #22
laurens
Member
 
Registered: Mar 2009
Posts: 65

Original Poster
Rep: Reputation: 15
Thanks Tinkster.
Code:
ftp -n -v immserv1.xx.xx.be << EOT
ascii
user UN pW
prompt
cd BACKUP
mget *.txt
ls
EOT
awk '{ sub("\r$", ""); print }' ftpservers.txt > unixfile.txt
awk 'NR%3==1{a[++i]=$0}END{for(f in a){print a[f], a[f] "_folderlist.txt"}}' unixfile.txt |
while read ipaddress flist
do
  while read dir
  do    
        echo $ipaddress and $dir
        ftp -n -v $ipaddress << EOT
        ascii
        user UN pW
        prompt
        get $dir
        EOT
  done < $flist
done
rm unixfile.txt
I have this new bash script that already has most of the functionalities I was looking for.
My $ipaddress and $dir are fetched correctly, only now I get the error error: ./bash.sh: line 25: syntax error: unexpected end of file which, as it seems, is provoked by the >> EOT
What can be done to solve this? Thx in advance
 
Old 05-14-2009, 02:39 PM   #23
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
The problem is with here-documents and indentation.
The EOT needs to be on a line by itself, not with
leading spaces ...


Cheers,
Tink
 
Old 05-14-2009, 02:40 PM   #24
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
The problem is with here-documents and indentation.
The EOT needs to be on a line by itself, not with
leading spaces ...


Cheers,
Tink
 
Old 05-14-2009, 07:31 PM   #25
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
also, if your use

set -xv

at the top of the script, you'll be able to see exactly what its doing.
http://www.tldp.org/LDP/abs/html/debugging.html
 
Old 05-15-2009, 07:01 AM   #26
laurens
Member
 
Registered: Mar 2009
Posts: 65

Original Poster
Rep: Reputation: 15
Thanks. Indeed, removing all the leading spaces solved it , especially for the EOT lines
 
  


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
FTP files to remote server with a shell script Pezzoni Linux - Software 2 06-27-2007 08:01 AM
FTP problem "connection closed by remote host" with RHEL4 and Windows 2003 hooijack Linux - Enterprise 0 03-23-2006 10:29 PM
Read a line in a txt file with bash orgazmo Programming 5 05-03-2005 08:10 AM
Read a line in a txt file with bash orgazmo Linux - Newbie 3 05-03-2005 05:16 AM
Remote desktop SuSE 8.2 -> Windows Server 2003 thacreeper Linux - Networking 2 08-26-2004 03:15 PM


All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration