I'm not even sure if this is possible. But if it is possible, I'd be interested in knowing the procedure.
I have SSH access on two remote servers. Occasionally, I need to move large numbers of files between them. I do this using the "wget" command. Problem? I have to sit in front of a computer to type in each "wget" command line. What I'd like to do (if possible) is create a text file in the directory of my second server where I want to copy files to that includes all the command lines ... like this:
wget http://serverone.com/file1.xxx
wget http://serverone.com/file2.xxx
wget http://serverone.com/file3.xxx
etc., etc., etc.
Then, I'd like to execute that text file as a batch file. Doable? If so, what would the command line look like to execute that batch file?
Regards,
J. Alec West
+ Reply to Thread
Results 1 to 12 of 12
-
-
Originally Posted by Baldrick
Regards,
J. Alec West -
In the Linux world, the command line is called the shell. The shell is called "BASH". Batch files are called shell scripts. You can probably use Perl, too.
You can easily transfer files between servers via SSH utilizing shell scripts.
There are many shell scripts you can find with Google, although most are oldish and somewhat limited. Try "BASH scripting" or "Linux shell scripts" to search for examples.
The Ubuntu forums, wiki's, man and help sites have good info that can easily be adapted to your distro.
Some O'Reilly books that have proven valuable to me are:
Linux Network Administrator's Guide
Linux Server Hacks
Linux in a Nutshell -
#!/bin/sh
FILES=" \
file1.foo \
file2.foo \
file3.foo \
--- \
file876876.foo";
# Allow for specification of individual file to be downloaded:
if [ -z "$1" ]; then
GETFILE=$FILES
else
GETFILE=$*
fi
for file in \
$GETFILE ;
do
wget http://www.someserver.com/$file ;
done
Two other simple ways -
wget http://server.com/file.foo && http://server.com/file2.foo && http://server.com/file3.foo ............
You can also use the mirror and accept list options of wget
wget -m --accept=rar,avi,zip,tgz,tar.gz,tar.bz2,foo,bar,blah http://server.com/
Wget has a few options. While logged into your server with putty, issue one of these commands -
wget --help
man wget
----------edit------------
If you just wanted to create a Linux batch file. Linux batch files are commonly called scripts or shell scripts. Bash is an entire shell - stands for Bourne Again Shell, there are many different shells. The SHELL is NOT called BASH! Bash is only one of many shell types
Once logged into your Linux server -
touch download.sh
(creates an empty file in the current directory called download.sh)
nano download.sh
(Nano is a simple text editor)
Type this inside the nano screen
#!/bin/sh
wget http://serverone.com/file1.xxx
wget http://serverone.com/file2.xxx
wget http://serverone.com/file3.xxx
etc., etc., etc.
Either -
sh download.sh
or
chmod +x download.sh
./download.shLinux _is_ user-friendly. It is not ignorant-friendly and idiot-friendly. -
Thanks to all. This is terra incognita stuff to me.
But, it appears very intuitive and very user friendly. I'll be moving a bunch of files in a couple of days and will try a few things then ... and will report on what happens when I do (grin).
Regards,
J. Alec West -
Doesn't it support wild cards?
#!/bin/sh
wget http://serverone.com/*.*
That would seem to be a lot easier -
Originally Posted by stiltman
Originally Posted by disturbed1
#!/bin/sh
wget http://serverone.com/file1.xxx;
wget http://serverone.com/file2.xxx;
wget http://serverone.com/file3.xxx;
Thank you for that VERY useful suggestion ... even though I had to "modify" it somewhat.
Regards,
J. Alec West -
Just a followup. Using the semi-colon at the end of the command line (after the filename) works fine in the script. However, after each command is executed, I notice a:
"; command not found"
error message. It doesn't affect the transfers at all. But, it does indicate that there's a "proper" way to end a command line. Anybody know what that proper way might be?
Regards,
J. Alec West -
The ; is not needed.
Did you create a text file, and write the commands in the text file, then execute it?
I just created this text file (shell script) then executed with success
Code:#!/bin/sh wget www.server.com/file1.xxx wget www.server.com/file2.xxx wget www.server.com/file3.xxx
wget --accept=exe,rar,zip -r www.server.com/
Or -
for file in file1.xxx file2.xxx file3.xxx;do wget www.server.com/$file;done
^^ If $file has spaces or special characters {The Super File.zip} you need to pass www.server.com/"$file" <-- notice the quotesLinux _is_ user-friendly. It is not ignorant-friendly and idiot-friendly. -
Originally Posted by disturbed1
In any case, the semi-colon inclusion, despite the error message, works for me ... so, I suppose I'll continue to use it.
Regards,
J. Alec West -
The character 0D hex is a carriage return. Sounds like the editor used the DOS convention of ending lines with CR/LF, instead of the Unix convention of just a Line Feed.
Steve
Similar Threads
-
Batch "file creation from a text file, Placed into a created directory
By Muther in forum ProgrammingReplies: 5Last Post: 24th Sep 2015, 18:29 -
Batch File. Need help
By Seritin in forum ProgrammingReplies: 1Last Post: 6th Apr 2010, 11:16 -
need some batch file help
By iamspuzzum in forum ComputerReplies: 6Last Post: 22nd Mar 2010, 16:19 -
Batch file
By Anurag in forum ComputerReplies: 16Last Post: 19th May 2009, 11:27 -
Batch file that can delete a specific file
By Dark_Raven in forum ProgrammingReplies: 1Last Post: 10th Jun 2008, 08:16