LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-24-2005, 06:07 AM   #1
tpreitano
LQ Newbie
 
Registered: Aug 2005
Posts: 7

Rep: Reputation: 0
set a line in a file as a variable


I have a file on a remote machine that has a list of the first three file names of a directory. How do I set line 1, line 2, and line 3 as a variable, so I can copy them. Here is my code so far........


ssh username@x.x.x.x <<END_SSH
cd /data/noaa/bigross
ls -tr | tail -3 | tee /tmp/bigross.log
(missing step to assign variable to lines)
exit
END_SSH
scp username@x.x.x.x:/data/noaa/bigross/$bigross1 /data/products/hrpt/bigross/


Thanks.
 
Old 08-24-2005, 06:09 AM   #2
tpreitano
LQ Newbie
 
Registered: Aug 2005
Posts: 7

Original Poster
Rep: Reputation: 0
mistake

Sorry, I meant last three files by time.......

TPR
 
Old 08-24-2005, 07:09 AM   #3
dub.wav
Member
 
Registered: Aug 2003
Location: Norway
Distribution: FC4
Posts: 83

Rep: Reputation: 20
If the copying is to be done at the server:
Code:
for file in $(ls -tr | tail -3 | tee /tmp/bigross.log)
do
    something with "$file"
done
If it has to be done on the client:
Code:
for file in $(ssh username@x.x.x.x 'cd /data/noaa/bigross; ls -tr | tail -3 | tee /tmp/bigross.log')
do
   something with "$file"
done
 
Old 08-24-2005, 08:35 AM   #4
tpreitano
LQ Newbie
 
Registered: Aug 2005
Posts: 7

Original Poster
Rep: Reputation: 0
I want to copy the files from this directory, /data/noaa/bigross, on the server. But I want to get only the files that are listed in bigross.log, not the log file itself. I know I need to run a seperate scp for each line in the file, but my problem is how do you read one line at a time in the log and set a variable to it.

Like so.........
Variable is file name on line one of log file
scp username@x.x.x.x:/data/noaa/bigross/$bigross1 /data/products/hrpt/bigross/

Variable is file name on line two of log file
scp username@x.x.x.x:/data/noaa/bigross/$bigross2 /data/products/hrpt/bigross/



Thanks
TPR
 
Old 08-24-2005, 09:10 AM   #5
dub.wav
Member
 
Registered: Aug 2003
Location: Norway
Distribution: FC4
Posts: 83

Rep: Reputation: 20
Code:
IFS=$'\n' # needed if any of the filenames contain whitespace
for file in $(ssh username@x.x.x.x 'cd /data/noaa/bigross; ls -tr | tail -3 | tee /tmp/bigross.log')
do
    scp username@x.x.x.x:/data/noaa/bigross/"$file" /data/products/hrpt/bigross/
done
 
Old 08-24-2005, 11:53 AM   #6
tpreitano
LQ Newbie
 
Registered: Aug 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks. Works Great.

I forgot to change to bash instead of csh, thats why I was having problems. Dumb mistake on my part.

TPR
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
how to set environment variable pranith Linux - Newbie 1 01-27-2005 11:23 PM
How to set a value of environment variable? ukrainet Linux - Newbie 1 12-28-2004 04:33 AM
Set variable with value of another Ephracis Programming 7 12-25-2004 10:34 AM
Set Environment Variable lloyd_stevens Linux - Software 1 07-30-2003 12:38 PM


All times are GMT -5. The time now is 11:16 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration