The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Tricky Shell script namishtiwari Shell Programming and Scripting 61 08-23-2007 06:26 AM
tricky search replace: Pls help. vaibhavs Shell Programming and Scripting 5 06-11-2007 02:44 PM
Tricky Sed bestbuyernc Shell Programming and Scripting 2 11-22-2005 01:03 PM
Tricky one... saabir Windows & DOS: Issues & Discussions 1 12-12-2002 05:34 PM
Tricky File Permission Question Hook Filesystems, Disks and Memory 3 07-16-2002 03:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-27-2006
budrito budrito is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 22
Tricky script question

Hi,

I'm in the midst of writing a UNIX script that sftp's files to an external host and am stuck with a problem. The problem is that the files created on my server as a order number that correlates to a sequence of directories on the remote host which is where the file should be ftp'ed.

Example:
My server filename:
myserver> /home/ 572011 O4MP ORDS 188406 V01 DT 20060608154548.txt

The 4th field (188406 ) in my filename correlates to a directory on the remote server where the file should be store. So on the remote server we should be sftp'ing this file to path

Remote Server:
remoteserver> /Test Documents/TestOrders/180001-190000/188001-189000/188401-188500/188406

The remote server has about 30+ directories and sub-directory ranges created to facilitate this file transfer. Remote server directory listings as range level and sub directories follow:
100001-110000 110001-120000
180001-190000 270001-280000 300001-310000 320001-330000
330001-340000 350001-360000 370001-380000 380001-390000
390001-400000 400001-410000 410001-420000 420001-430000
430001-440000 440001-450000 450001-460000 460001-470000
470001-480000 480001-490000 490001-500000 500001-510000
510001-520000 520001-530000 530001-540000 540001-550000
550001-560000 560001-570000 570001-580000 580001-590000
590001-600000 600001-610000

So another example would be that if we received a filename:
/home/ 572011 O4MP ORDS 588406 V01 DT 20060608154548.txt (Note: 588406 is the directory to be stored on remote site as explained above)

How can I make the script smart enough for it to look at the forth field in my file name and sftp it on the remote server path:
remoteserver> /Test Documents/TestOrders/580001-590000/588001-589000/588401-588500/588406

This is for #!/bin/sh, #!/bin/csh or #!/bin/ksh and based on HP-UX 11i.

Your assistance would be greatly appreciated.

Thanks.
  #2 (permalink)  
Old 06-28-2006
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Here's one hint:
Using recent version of ksh or bash, you can do this:
Code:
fullname="/home/ 572011 O4MP ORDS 188406 V01 DT 20060608154548.txt"
file="${fullname##*/}"
read _ _ _ dir _ <<<$file
echo $dir
If you have an older version of either ksh or bash, the following works, but is not as aesthitically pleasing (to me )
Code:
fullname="/home/ 572011 O4MP ORDS 188406 V01 DT 20060608154548.txt"
file="${fullname##*/}"
echo $file| read _ _ _ dir _
echo $dir
Please post back if you run into further problems implementing this...
  #3 (permalink)  
Old 06-29-2006
budrito budrito is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 22
Hi,

The problem with the above is that it doesn't give me the full path of the range directory on teh remote server. The output only gives me 188406 whereas I would be after something silimar to:

/Test Documents/TestOrders/180001-190000/188001-189000/188406

thks.
  #4 (permalink)  
Old 06-30-2006
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Well, shy of doing the entire project for you, I'm willing to give some bits up here and there...

How do you determine the other directory names? Are they static (non-changing) or dynamic (could possibly be different for each file)?

And importantly, what shell are you using?
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 12:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0