Sort while you are in FTP!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort while you are in FTP!
# 1  
Old 10-21-2011
Sort while you are in FTP!

Hi All,

I'm a newbie in Perl.. is it possible to sort the file in ascending order while you are in the SFTP then get the file in the top then process.. and son on and so on..

ex.
Server 1
file2
file1
file3

I'm here in Server 2. what i'm going to do is sort the file in Server 1 then get the top file and process it.

ex.
let's assume the the file now is already sorted
file1 ----> i'm going to get this file in server 1 after i sorted it then process it.
file2 ----> after i'm done on the process i'm now going go get the file2 to proces.
file3 ----> same process.

Is it possible in perl? because i don't have any idea to do this? T_T

Please advise,
Thanks,
# 2  
Old 10-21-2011
Solution in shell .. Sample script ..
Code:
ssh username@server1 "ls dir_path | sort -u" > tempfile
while read line
do
     ### include ftp-code here ###
     mget $line
done<tempfile

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 10-21-2011
Thanks jayan jay.. I'm going to try this now using Shell..

---------- Post updated at 03:03 PM ---------- Previous update was at 02:57 PM ----------

I'm just wondering jayan jay is it possible in shell to get the sorted file one by one? like in my example?

ex.
get file1 in server 1 > process > done
get file2 in server 1 > process >done

before getting the file2 you must first complete the process of file1.

is it possible? because i don't have any idea.

Please advise.
Thanks,
# 4  
Old 10-21-2011
Yes it is possible .. Include those code also in while loop.
Code:
ssh username@server1 "ls dir_path | sort -u" > tempfile
while read line
do
     ### include ftp-code here ###
     mget $line
     ### include that process code here ###
     sh /path/to/the/ftp/file/$line
     [ $? -eq 0 ] && echo "Success $line" || exit 
done<tempfile

This User Gave Thanks to jayan_jay For This Post:
# 5  
Old 10-24-2011
Thank you very much Sir jayan jay. I'm going to try this..

---------- Post updated at 06:57 PM ---------- Previous update was at 03:30 PM ----------

Hi, Sir jayan

Code:
ssh username@server1 "ls dir_path | sort -u" > tempfile

is working. it output the sorted file in tempfile. however how can i process the head of my file while i'm in the sftp? is that possible?

THanks,

---------- Post updated at 08:21 PM ---------- Previous update was at 06:57 PM ----------

Hi Sir,

I'm just wondering if what is the use of this?

Code:
### include that process code here ###      sh /path/to/the/ftp/file/$line --> this means i'm going to run a script?      [ $? -eq 0 ] && echo "Success $line" || exit

# 6  
Old 10-24-2011
I am just giving that as an example ..

Not only sh .. You can do the required task/work with ftp'ed file ..
# 7  
Old 10-25-2011
Hi Sir jayan jay,

i tried you code but it cause me an error. " No such file or directory"

here is my code.
Code:
HOST='123456.789.156'
USER='User'
PASSWD='password'
DEC_DIR="/home/test/"
ORACLE_DEV="home/dev/"
TESTDEV="/home/dev"

ssh ${USER}@${HOST} "ls ${DEC_DIR} | sort -u" > nik.temp
while read line
do
        sftp ${USER}@${HOST} <<-EOF
        cd ${DEC_DIR}
        get $line
        EOF
        awk -F "," '{ if ($10 ="YES")
               print $1",",$2",",$4",",$5",",$6;}' $line > ${TESTDEV}$line.dat | awk -F "," '{print $2",",$4}' $line > ${ORACLE_DEV}$line.ns

done <nik.temp
exit

my problem here is print $1",",$2",",$4",",$5",",$6;}' $line is not outputting in ${TESTDEV}

and i tried to use else and another if for "NO" but it's error.

please advise,

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use sort to sort numerical column

How to sort the following output based on lowest to highest BE? The following sort does not work. $ sort -t. -k1,1n -k2,2n bfd.txt BE31.116 0s 0s DOWN DAMP BE31.116 0s 0s DOWN DAMP BE31.117 0s 0s ... (7 Replies)
Discussion started by: sand1234
7 Replies

2. UNIX for Beginners Questions & Answers

Difference of Sort -n -k2 -k3 & Sort -n -k2,3

Hi, Could anyone kindly show me a link or explain the difference between sort -n -k2 -k3 & sort -n -k2,3 Also, if I like to remove the row with repetition at both $2 and $3, Can I safely use sort -u -k2 -k3 Example; 100 20 30 100 20 30 So, both $2 and $3 are same and I... (2 Replies)
Discussion started by: Indra2011
2 Replies

3. UNIX for Dummies Questions & Answers

Sort directories in 'D' on FTP server

Hello, There are 3 directories on FTP server with format yyyymmddhhmiss. Can someone please let tell me how do I sort these directories in descending order. I only have get the files from the latest directory on FTP server. ftp>ls -l 20150707011229 20150707061229 20150707131225 ... (2 Replies)
Discussion started by: pavan_test
2 Replies

4. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

5. Shell Programming and Scripting

Help with sort word and general numeric sort at the same time

Input file: 100%ABC2 3.44E-12 USA A2M%H02579 0E0 UK 100%ABC2 5.34E-8 UK 100%ABC2 3.25E-12 USA A2M%H02579 5E-45 UK Output file: 100%ABC2 3.44E-12 USA 100%ABC2 3.25E-12 USA 100%ABC2 5.34E-8 UK A2M%H02579 0E0 UK A2M%H02579 5E-45 UK Code try: sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Discussion started by: perl_beginner
2 Replies

6. Shell Programming and Scripting

Alternate to sort --random-sort

sort --random-sort The full command is path=`find /testdir -maxdepth 1 -mindepth 1 -type d | ***Some sort of sort function*** | head -1` I have a list I want to randomly sort. It works fine in ubuntu but on a 'osx lion' sort dosen't have the --random-sort option. I don't want to... (5 Replies)
Discussion started by: digitalviking
5 Replies

7. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

8. Shell Programming and Scripting

Is it Possible to sort a list of hexadecimal numbers using "sort" command?

Hello Everybody :) !!!. i have question in mind, is it possible to sort a list of hexadecimal numbers using "sort" command? (9 Replies)
Discussion started by: Kesavan
9 Replies

9. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

10. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies
Login or Register to Ask a Question