Tricky script question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tricky script question
# 1  
Old 06-27-2006
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  
Old 06-28-2006
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 Smilie )
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  
Old 06-29-2006
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  
Old 06-30-2006
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tricky BASH quoting question

I have some data files that I can identify by a certain pattern in the names using find. Every one of those data files has an XML file associated with it (can be multiple data files per XML file). The XML file is always up one directory from the data file(s) in a folder calledRun##### -... (12 Replies)
Discussion started by: Michael Stora
12 Replies

2. UNIX for Dummies Questions & Answers

Tricky GREP question..

I have some large login files that I need to extract (user)@(server) from. Where it gets tricky is that there is usually more than one '@' sign on each line(although it does have a leading space if it's not part of the (user)@(server) string), I need only the (user)@(server) section, I need only... (6 Replies)
Discussion started by: Mordaris
6 Replies

3. Shell Programming and Scripting

Another tricky sed or awk question

This post is in reference to https://www.unix.com/shell-programming-scripting/137977-tricky-sed-awk-question-post302428154.html#post302428154 I am trying to go the opposite direction now: I have the following file: a,b,C,f,g a,b,D,f,g a,b,E,f,g h,i,J,k,l m,n,O,t,u m,n,P,t,u m,n,Q,t,u... (3 Replies)
Discussion started by: awayand
3 Replies

4. Shell Programming and Scripting

Tricky sed or awk question

Hello everyone, unfortunately I am no unix nor scripting guru, which is why I am asking for help here. I am trying to reformat a .csv file using sed or awk which has the following format: a,b,C-D-E,f,g h,i,J,k,l m,n,O-P-Q-R-S,t,u v,w,X-Y,z,a It's basically a 5-field text file which has an... (7 Replies)
Discussion started by: awayand
7 Replies

5. Shell Programming and Scripting

Tricky - Need help on Shell script variables

Hi, I have a requirement in which i have to read a csv file and put data in certain set of variables: File content: VP-DTL-REC-CNT, ,854840,0.00,VP-PAID-AMT, ,0,32280885.17,VP-PAT-PAID-AMT, ,0,9930244.32,VP-PAID-REV-CNT, ,484927,0.00,VP-REJ-CNT, ,369913,0.00, , ,0,0.00, , ,0,0.00, , ,0,0.00, ,... (3 Replies)
Discussion started by: shantoshkumar
3 Replies

6. Shell Programming and Scripting

Linux: Writing a tricky script to check connectivity

So, first and foremost, I'm having issues with my internet connection. Periodically, the connection drops across the network. The fix is simple enough: restart the modem. However, this gets old when the connection dies out every hour. I can hit my surfboard on 192.168.100.1, and navigate to a... (5 Replies)
Discussion started by: kungfujoe
5 Replies

7. UNIX for Dummies Questions & Answers

Tricky Quotation Question

Hi, I am at a point in my script where I defined the number of the command line parameter I would like to set a variable equal to: parameter_number=14 I would then like to set a variable equal to the correct parameter: variable=$parameter_number The issue here is that {} is required... (2 Replies)
Discussion started by: msb65
2 Replies

8. Shell Programming and Scripting

Tricky Shell script

The Problem is mentioned below (61 Replies)
Discussion started by: namishtiwari
61 Replies

9. Windows & DOS: Issues & Discussions

Tricky one...

Here's my problem: I have a laptop running Windows XP Pro with no internal CD or Floppy drives. I want to install Linux on it. I don't care about the Windows XP Pro installation, in fact I would like to install Linux over the entirety of the HD. However I cannot boot from any external CD drive... (1 Reply)
Discussion started by: saabir
1 Replies

10. Filesystems, Disks and Memory

Tricky File Permission Question

I'm trying to answer the following question about file permissions in Unix. Consider a file with the following permissions: rwx---r-- I am not the owner of this file, but I am a member of the group of this file. My question is: do I have read access to this file? I thought... (3 Replies)
Discussion started by: Hook
3 Replies
Login or Register to Ask a Question