How to store results of ls in ftp?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to store results of ls in ftp?
# 1  
Old 07-12-2012
How to store results of ls in ftp?

Hi,
I want to store the results of running ls in a directory on a remote host using ftp.

For example,

Code:
#!/usr/bin/ksh
 
ftp -n hostx <<EOF
user username password
 
ls /tmp/RandomFiles.*
 
#I need to put the results of that ls command into some file, so I can get the last file in that list

The ultimate goal is to get the LAST RandomFiles file. Since I can't just tail -1 in ftp, I'm trying to store the results of ls in a file and then get the last entry from that file, then finally ftp that exact entry from the host again.
# 2  
Old 07-12-2012
Redirection works in usual way...

Code:
ftp -n hostx <<EOF >> ftp_out.txt

# 3  
Old 07-12-2012
thank you, sorry if the question was stupid, im very new to this..

---------- Post updated at 11:36 AM ---------- Previous update was at 11:28 AM ----------

Quote:
Originally Posted by clx
Redirection works in usual way...

Code:
ftp -n hostx <<EOF >> ftp_out.txt

Also, could you tell me how I can extract the file name from the last line of ftp_out.txt?

The last line of ftp_out.txt is:

Code:
-rw-r--r--   1 root       sys          42512 Jul 11 19:25 /tmp/RandomFile.0711

I need to get RandomFile.0711, then get that file using ftp from hostx.
# 4  
Old 07-13-2012
Try...
Code:
$ cat ftp_out.txt
-rw-r--r--   1 root       sys          42512 Jul 11 19:25 /tmp/RandomFile.0711

$ set -- $(<ftp_out.txt)

$ basename ${!#}
RandomFile.0711

$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I want to add a variable for the results from the formula of one variable and results of another var

Good morning all, This is the file name in question OD_Orders_2019-02-19.csv I am trying to create a bash script to read into files with yesterdays date on the file name while retaining the rest of the files name. I would like for $y to equal, the name of the file with a formula output with... (2 Replies)
Discussion started by: Ibrahim A
2 Replies

2. UNIX for Dummies Questions & Answers

How to store "scp" results in a database table?

Hi, When I use scp to copy a file from other location, I get the output like filename, time taken etc on console. I want to store that into a database table (in oracle). Could someone give me some pointers on how to achieve this? Regards, Sachin Vaidya (1 Reply)
Discussion started by: notthatsachin
1 Replies

3. Shell Programming and Scripting

Store results in table

Hello everyone, I have a shell script, which connects to the database and runs .sql file. after executing of .sql file, i need to store the results in error table. How can i achieve this one? could you please give your suggestions. here is my code. #!/bin/sh #set -vx SCHEMA_NAME=$1... (1 Reply)
Discussion started by: Rami Reddy
1 Replies

4. Shell Programming and Scripting

How to store results of multiple sql queries in shell variables in ksh?

Hi, I have a script where I make a sqlplus connection. In the script I have multiple sql queries within that sqlplus connection. I want the result of the queries to be stored in shell variables declared earlier. I dont want to use procedures. Is there anyway else. Thanks in advance.. Cheers (6 Replies)
Discussion started by: gonchusirsa
6 Replies

5. Shell Programming and Scripting

Can ctag and cscope support recording search results and displaying the history results ?

Hello , When using vim, can ctag and cscope support recording search results and displaying the history results ? Once I jump to one tag, I can use :tnext to jump to next tag, but how can I display the preview search result? (0 Replies)
Discussion started by: 915086731
0 Replies

6. Shell Programming and Scripting

New file should store all the 7 existing filenames and their record counts and ftp th

Hi, I need help regarding below concern. There is a script and it has 7 existing files(in a path say,. usr/appl/temp/file1.txt) and I need to create one new blank file say “file_count.txt” in the same script itself. Then the new file <file_count.txt> should store all the 7 filenames and... (1 Reply)
Discussion started by: pr293
1 Replies

7. Shell Programming and Scripting

Not able to store the results of perl recursive function when applied under for loop

Hi Perl Gurus , need URGENT HELP PLEASE !!!!! I have one recursive Perl function which takes path of any directory as argument and returns array containing all the sub folders inside it recursively. Now the problem is that it works well if i use it with one time but the problem is that when... (0 Replies)
Discussion started by: anthriksh2000
0 Replies

8. UNIX for Dummies Questions & Answers

store SQL statements and results in a file

Hello Guys... I want a small help from you guys. Actually in Oracle, we are having a utlity called spool through which can store whatever SQL statements executed and other queries and the output of those queries in a file So, similarly in Unix, if I start a session executing a number of Unix... (2 Replies)
Discussion started by: mraghunandanan
2 Replies

9. Shell Programming and Scripting

Grep results to store in a shell variable

I have the results of a grep with -n store in a shell variable ie VAR=`grep -n -e 'PATTERN' file` How ever I am missing the line breaks in the variable , How do I store the resualts of grep with many lines in to a variables. I want the varable should be the sawmway as we do the grep grep... (3 Replies)
Discussion started by: jojan
3 Replies

10. Shell Programming and Scripting

store awk results in a variable

I try to get the month (of last save) and the filename into a variable, is this possible ? something like this : for month in `ls -la | awk '{print $6}'` do if ] then a=filename of the matching file cp $a /Sep fi thanks, Steffen (1 Reply)
Discussion started by: forever_49ers
1 Replies
Login or Register to Ask a Question