LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-09-2014, 04:39 AM   #1
massy
Member
 
Registered: Nov 2013
Distribution: CentOS 6.4
Posts: 209
Blog Entries: 1

Rep: Reputation: Disabled
A script for uploading a file via scp in a loop


I've used this code to upload a package to some hosts that their IPs are in the IPvar, but it is runs only one time!

Code:
#!/bin/bash
while read IP

do
     /usr/bin/scp /home/farid/Package/sudo_1.8.5p2-1+nmu1_i386.deb check@$IP:/home/check

done < IPvar
 
Old 06-09-2014, 05:20 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Are you saying you have multiple lines in the IPvar file but only the first is processed?

I just tried something almost identical and it worked. I could imagine you'd have a problem if the program in the loop read STDIN and deprived the shell of further input from IPvar.
 
Old 06-09-2014, 06:52 AM   #3
massy
Member
 
Registered: Nov 2013
Distribution: CentOS 6.4
Posts: 209

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by linosaurusroot View Post
Are you saying you have multiple lines in the IPvar file but only the first is processed?

I just tried something almost identical and it worked. I could imagine you'd have a problem if the program in the loop read STDIN and deprived the shell of further input from IPvar.
yes I have some IPs in IPvar
 
Old 06-11-2014, 08:49 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

scp uses ssh which messes up reading from standard input. Remember both ssh and scp can ask for password. And ssh sends stdin to the computer it connects to. Use a for loop instead:

Code:
#!/bin/bash
for IP in $IPvar ; do
    /usr/bin/scp /home/farid/Package/sudo_1.8.5p2-1+nmu1_i386.deb check@$IP:/home/check
done
 
1 members found this post helpful.
Old 06-11-2014, 09:07 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
what does this yeild:

Code:
#!/bin/bash
echo $IPvar
while read IP

do
     echo /usr/bin/scp /home/farid/Package/sudo_1.8.5p2-1+nmu1_i386.deb check@$IP:/home/check

done < IPvar
 
1 members found this post helpful.
Old 07-03-2014, 06:05 AM   #6
jungliztik
LQ Newbie
 
Registered: Jul 2014
Posts: 2

Rep: Reputation: Disabled
Sounds like you want something like:
Quote:
maxjobs = 10

foreach line in the file {
jobsrunning = 0
while jobsrunning < maxjobs {
do job &
jobsrunning += 1
}
wait
}

job ( ){

for IP in $( cat IPvar )
do
/usr/bin/scp /home/farid/Package/sudo_1.8.5p2-1+nmu1_i386.deb check@$IP:/home/check
done
}
Borrowed from MrC's post on http://ubuntuforums.org/showthread.php?t=382330 as I'm on my phone. I've done similar before and this method would allow you some controlled concurrency to your activity.

Last edited by jungliztik; 07-03-2014 at 06:10 AM.
 
  


Reply



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 loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
[SOLVED] permision error while uploading file through scp mia_tech Linux - General 2 03-16-2014 02:02 PM
to scp to multiple Linux systems by using for loop script dezavu Red Hat 8 05-22-2012 11:43 PM
Permissions for file uploading script in php emab Programming 7 08-31-2008 06:53 AM
Executing a script when uploading a file to a SAMBA SERVER rafa_gallego Linux - Server 4 01-18-2008 05:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:57 AM.

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
Open Source Consulting | Domain Registration