[olug] Simple local network script

Will Langford unfies at gmail.com
Sun Jun 18 20:18:45 UTC 2006


On 6/17/06, Sean Kelly <smkelly at zombie.org> wrote:
>
> On Sat, Jun 17, 2006 at 08:23:08PM -0500, Jack wrote:
> > Sorry to bother you guys (and gals?), but I could use a simple script
> > for the following:
> >
> >     I am using sftp to move files from one computer to another in my
> > home network.  I use MandrivaLinux 2006 on both machines.
> >     I always enter in the same commands on the same machine.  The
> > commands are:
> >
> > sftp 192.168.1.214
> > (then I put in the password and when I am in the sftp shell I type:)
> > put /home/jd/Sneakernet/* /home/jd/Sneakernet
> > bye
>
> First off, you could be using `scp` instead of `sftp`. SCP is a
> non-interactive way to copy files with SSH. So, you'd change the above by
> doing:
>
> $ scp /home/jd/Sneakernet/* @192.168.1.214:/home/jd/Sneakernet
>
> As for eliminating the password, I'd suggest you look into building a new
> SSH key without a password. This article describes it:
> http://www.linuxjournal.com/article/8600
>
> So, as for a simple shell script... Something along the lines of:
> --SNIP--
> #!/bin/sh
> /usr/bin/scp ~jd/Sneakernet/* @192.168.1.214:~jd/Sneakernet/
> --SNIP--
>
> --
> Sean Kelly         | PGP KeyID: D2E5E296
> smkelly at zombie.org | http://www.zombie.org
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug
>

Or, if you prefer to still use sftp for doing this and not scp (although scp
is the proper choice), you can use sftp with the ' -b ' option to have it
read a 'batch' of commands from a file rather than from standard in.  You'll
still need to generate your keys (as mentioned by Sean's email) so you don't
have to supply password.  About the only reason to use sftp is if you needed
the few more commands sftp offers instead of just a file copy (permissions
etc). A sample would be something like:

==== contents of  batch.sftp ====
cd /home/jd/Sneakernet
lcd /home/jd/Sneakernet
put -P *
bye
==== end ====

Note, the -P means to copy permissions of the original files.

==== contents of sftpbatch.sh ====
#!/bin/bash
DATE=`date +%Y.%m.%d-%H:%M:%S`
sftp -b batch.sftp 192.168.214 &> sftpbatch-${DATE}.log
==== end ====

-Will



More information about the OLUG mailing list