Hello, On Mon, 10 Aug 2009, Chuck Payne wrote:
Sorry if this question seem a bit silly, but I am still very much a newbie when it come some to scripting.
I want to write a shell script that does some scp of files, but I like
Your script does something else entirely. It uses perl's SFTP Module. Straightforward would be: srcdir=/tmp destdir=/tmp file="$(hostname)$(date '+%m%d%Y').tgz" scpjvm () { test -r "${srcdir}/${file}" || { echo "Cannot read source file '${srcdir}/${file}'!" >&2 exit 1; } scp "${srcdir}/${file}" "toor@mars.myhost.com:${destdir}" } You need a key-based ssh setup for this though. Which is probably better anyway. And you can pipe a tar through ssh: tar cvpPz FILES_AND_PATHS_AS_USUAL | \ ( ssh user@desthost sh -c 'cat > /tmp/destfile.tar.gz' ; ) (or unpack the tar on the remote site with | ( ssh user@desthost tar xpvPz ; ) ) With non-GNU-tar Versions, you might have to use the explicit '-f -' for the filenames on one or both ends.
to use both bash and perl. Could I do some thing this, how would I got about mixing shell, python, perl and other things with in a script.
==== COMPLETELY AND UTTERLY UNTESTED -- just for ideas ==== #!/usr/bin/perl -w use strict; use POSIX qw(strftime); use Net::SFTP; use Archive::Tar; my $workdir = "/tmp"; my $localhost = (gethostent())[0]; my $date = strftime("%m%d%Y", localtime()); my $file = $localhost . $date . ".tgz"; my $dry_run = 0; ## supposed to be set via an option -> cf. Getopt::* sub runcmd { ### about everything you need to make 'system' comfortable my $ret = 0; if( ! $dry_run ) { print "\n", "=" x 68, "\nRunning: ", join(" ", @_), "\n\n"; system(@_); $ret = $?; if( $ret == -1 ) { print STDERR "failed to execute: $!\n"; } elsif ($ret & 127) { printf STDERR "\nchild died with signal %d, %s coredump\n", ($ret & 127), ($ret & 128) ? "with coredump" : ""; } } else { print "\n", "=" x 68, "\nWould run: ", join(" ", @_), "\n\n"; } return $ret == 0; } sub scpjvm () { my $host = "mars.myhost.com"; my %args = ( user => 'toor, password => '1234567', debug => 'true' ); my $sftp = Net::SFTP->new($host, %args); ### should your 'get' not be a 'put' instead? Or why do you ### locally create the archive just to overwrite it afterwards? $sftp->put( $workdir . "jvm." . $file, $workdir . "jvm." . $file) or die "$!\n"; return 1; } chdir($workdir) or die "$!"; ### using 'tar' is probably faster than Archive::Tar anyway ... runcmd("tar", "czvpPf", $file, qw( /etc/httpd /opt/jboss/jboss/bin/ /opt/jboss/jboss/server /usr/local/bin --exclude *log* --exclude *nohup* )) or die "$!\n"; if( scpjvm() ) { unlink($file); } ==== HTH, -dnh -- Well, merry frelling christmas! -- Aeryn Sun, Farscape - 4x13 - Terra Firma -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org