lawlRedneck

July 8, 2009

sftp/scp scripting

Filed under: Uncategorized —— elmidgeto @ 4:15 pm

The situation: I need to move files from one server to another using onlythe OpenSSH tools. All authentication/authorization is done via public key handshakes.

The restrictions: I cannot use expect or any other scripting language beyond shell scripts.

The goal: To minimize the number of characters I need to type and provide a platform for our batch guy to build on for the automated transfers.

And without further ado, have at thee. (Note: I did remove username, sftp connection string, and the root paths from my script to eliminate identification)

#!/bin/bash
######################################################
###### Utility script for Pushing/Pulling files ######
###### from the enterprise sftp solution. ############
######################################################

##################################################
############# SETTING THE VARIABLES ##############
##################################################

TYPE=$1
FILENAME=$2

USER=”"
SFTP=”"
BASEPATH=”"

SFTPPATH=$BASEPATH
LOCALPATH=`pwd`

MAX=$#
ARGS=(”$@”)

for ((COUNT=2; COUNT < MAX; COUNT++))
do
 if [ ${ARGS[$COUNT]} == “-s” ];then
      SFTPPATH=$SFTPPATH/${ARGS[$COUNT+1]}
      COUNT=$COUNT+1
 
 elif [ ${ARGS[$COUNT]} == “-l” ];then
      LOCALPATH=${ARGS[$COUNT+1]}
      COUNT=$COUNT+1 
 fi
done

##################################################
########### COPY FROM THE SFTP SERVER ############
##################################################

if [ $TYPE == "GET" ]; then
     scp $USER@$SFTP:$SFTPPATH/$FILENAME $LOCALPATH/$FILENAME

##################################################
############ COPY TO THE SFTP SERVER #############
##################################################

elif [ $TYPE == "PUT" ]; then
     scp $LOCALPATH/$FILENAME $USER@$SFTP:$SFTPPATH/$FILENAME

##################################################
########## DELETE FROM THE SFTP SERVER ###########
##################################################

elif [ $TYPE == "DEL" ]; then
     sftp -b /dev/stdin $USER@$SFTP <<INP
     cd $SFTPPATH
     rm $FILENAME
     ls
     bye
INP

##################################################
############### SCRIPT ARGS HELP #################
##################################################

elif [ $TYPE == "-h" ]; then
     echo “  sftp_util syntax is:”
     echo “  ./sftp_util.sh <GET|PUT|DEL|-h> <FileName> [-s] [-l]”
     echo “  GET GET is used to retrieve a file from the remote server.”
     echo “  PUT PUT is used to place a file on the remote server.”
     echo “  DEL DEL is used to delete a file from the remote server.”
     echo “  -h -h is used to print this help menu.”
     echo “  -s -s <sftp server path of/to file, do not include a leading ‘/’ (ex. test/test2)>”
     echo “  -l -l <sftp server path of/to file>”
 
else
     echo “Please use ./sftp_util.sh -h for help”
fi

Usage goes a little something like this:

server1$> ./sftp_util.sh PUT file -s test/empty_dir -l /home/user

server2$> ./sftp_util.sh GET file -s test/empty_dir -l /here

server2$ ./sftp_util.sh DEL file -s test/empty_dir

 

Nothing overly fancy, just a quick little script to save me time and have a bit of fun on a slow work day.

May 28, 2009

The Nashville Life

Filed under: Uncategorized —— elmidgeto @ 7:05 pm

I suppose I ought to post something so people don’t off and assume I died on the barren plains of Wyoming.

Some of you may be aware I moved to Nashville, Tennessee for a job offer doing something similar to what I was doing in Wyoming (and if you weren’t aware of it, you are now).

Work has been keeping me busy so I haven’t been up to much else. I somehow managed to get promoted with like seven times the work and no real promotion, but I wound up being responsible for establishing and testing the connections between our application and external agencies and providers, in addition to my other work.

So aside from the oppressive, gawdawful heat and humidity, the south is actually a nice place. People are really friendly (I can’t count the number of random honest to ganesh conversation that start in the elevator) even if they can’t drive. Still looking for my camera to prove to the shirtninja that the scenery down here is far surpassing anything to be found in South Dakota.

Other than that, wedding thingy coming up, and then when I return hopefully I will muster the motivation to finish my rifle, do some load development, and shoot a barrel or two out of it.

February 12, 2009

Listening to what now?

Filed under: Uncategorized —— elmidgeto @ 6:23 pm

I’ve always had a rather ecclectic taste in music. My music collection has everything from Acid Trance to Jazz to classical to Country (and Western, probably one of very few my age that still knows the difference =P) and even more.

 

Lately I’ve been on a bit of an odd kick, even for me. The last few days I’ve been listening to The Cruxshadows, an Industrial band from over europe way.

http://www.youtube.com/view_play_list?p=7F12EEC7D7BEF462

 One nice thing about youtube is it allows you to explore new music and set up playlists and favorites so you don’t have to go to the hassle and hit/miss of trying to pirate music before deciding to buy it. There’s the youtube playlist of most of the Cruxshadows songs I have been listening to lately. I highly reccomend Winterborn, Eye of the Storm, A Promise Made, and Dragonfly. Simply some of the best musical lyrics I have ever heard.

February 6, 2009

blargh…

Filed under: Uncategorized —— elmidgeto @ 1:42 pm

Been a while since I have posted anything, let alone anything of note. Not for lack of “interesting” things happening no doubt, just haven’t had the motivation.

Interesting happenings since October:

Busy at work -> project cancelled.
Broke my foot.
Laid off in the RIF.
Spent a bunch of time with family over christmas, it was amusing watching my nephew go nuts anytime anyone went near my foot since he had been told in no uncertain terms to stay away from it.
Spent a few weeks looking for a job.
Was offered a position at a different project with the same company I worked for.
Accepted said job and have been impatiently waiting for paperwork to make its way through HR so I can be reinstated.

So, soon I will be commuting from Wyoming to Tennessee and waiting for some form of relocation assistance to move down to Nashville permanently or until I get RIF’d or transferred again.

lawlRedneck is proudly powered by WordPress running on http://blogs.dootdoot.com.
Create a new blog and join in the fun! Entries (RSS) and Comments (RSS).