Not looping or creating files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not looping or creating files
# 1  
Old 06-13-2013
Not looping or creating files

So my script is supposed to repeat for every server in my file, but as of now it is getting stuck on my awk commands

Code:
# Read file cred.txt (with one IP per line), connect to servers (one at a time), and download directory listing
i=1
param=$(sed -n "{$1}p" $parm_dir/cdm_param.txt) #Get the last saved parameter in cdm_param.txt (Date in format YYYYMMDD when the script was last successfully run)
param=$(date -d $param+%Y-%m) # Convert YYYYMMDD to YYYY-DD
while read line; do
	host=$line
	ssh $user@$host ls -1 $was7sourcedir/$src_file_name$param'*' > $workdir/ftpList$i.txt
	awk -F '{print substr($line,length($line)-14,10)}' ftpList$i.txt > Dates$i.txt #Save the date part of each file name
															  #in the directory listing downloaded previously.
	awk -F '{print substr($line,length($line)-31,27)}' $workdir/ftpList$i.txt > $workdir/Files$i.txt	#Save the name of each file.
		linenum=0 #Auxiliary variable for sed. Will be used to match the line where the condition is satisfied with the corresponding file.
		
		while read list; do
		linenum=$((linenum+1))
		date_of_file=$(date -d "$list" +%Y%m%d) #Convert the modification datetime of each file to format YYYYMMDD
		    if [ "$date_of_file" -gt "$param" ] ; then #Compare with the last saved parameter
			file=$(sed -n "${linenum}p" $workdir/Files$i.txt)	#If the condition is satisfied, use sed to get the name of the file
														#in the same line of Files$i.txt.
		while read line2; do	#Connect again and download file when the above condition has been satisfied.
			sftp $user@$host <<END_RETRIEVE
			cd $was7sourcedir
			get $file
			quit
END_RETRIEVE

Once it creates the file with the list of filenames...it doesnt do anything else. It tells me the syntax in my awk command is wrong.

ftpList.txt
^syntax error.

It specifically points at the .txt a part of my line where it says the syntax error is.
It doesnt continue running. It doesnt go back and do the same for the other servers. It just quits.

Any ideas?
# 2  
Old 06-13-2013
do not use single quote('):

ssh $user@$host ls -1 $was7sourcedir/$src_file_name${param}* > $workdir/ftpList$i.txt
# 3  
Old 06-13-2013
that part is working fine though. It does exactly what I want it to do.

The part not working is the awk portion of the code.

Its telling me there is a syntax error
Code:
awk -F '{print substr($line,length($line)-14,10)}' ftpList$i.txt > Dates$i.txt #Save the date part of each file name
															  #in the directory listing downloaded previously.
	awk -F '{print substr($line,length($line)-31,27)}' $workdir/ftpList$i.txt > $workdir/Files$i.txt	#Save the name of each file.
		linenum=0 #Auxiliary variable for sed. Will be used to match the line where the condition is satisfied with the corresponding file.

This the part causing issues. My files arent being creating. The datefile is empty.
# 4  
Old 06-13-2013
you can not use shell variable directly in awk. try this:

Code:
awk -F '{print substr($line,length('$line')-14,10)}' ftpList$i.txt > Dates$i.txt

Moderator's Comments:
Mod Comment Use code tags!

Last edited by radoulov; 06-13-2013 at 11:55 AM..
# 5  
Old 06-13-2013
Not working. Still giving me the same error
# 6  
Old 06-13-2013
sorry, I forgot the first one:

Code:
awk -F '{print substr('$line',length('$line')-14,10)}' ftpList$i.txt > Dates$i.txt

# 7  
Old 06-13-2013
Oh I know. I corrected it when I saw it. Its just still telling me there is an error.
I have awk and sed on my server and its seeing my ftpList.txt as an error
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping through files in pairs

Hi all, Please guide. It has to do with parsing the input file names. I have a fairly large number of files, I want to do some operations on them in a pairwise fashion (every file has a pair). The names are in the following pattern, with the pairs of files named with _1 and _2 , the... (4 Replies)
Discussion started by: newbie83
4 Replies

2. Shell Programming and Scripting

Looping through Files

Hi all , I am new on this forum . I have to face a particoular implementation issue and I need some help . Requirement : I need to read a particoular file (an xml file) and after reading it I need to call an Oracle Stored Procedure passing the content of the file as paramenter , in order... (3 Replies)
Discussion started by: Kolas79
3 Replies

3. Shell Programming and Scripting

looping through files with different extensions

Hi all, I am trying to make a for loop invoking files with different extensions (*.ugrd and *.vgrd) and I cant just make it work. Cant figure out how to load the files so as to use them in subsequent commands like the ones in this pseudo code. the files are arranged such that in one date for... (8 Replies)
Discussion started by: ida1215
8 Replies

4. UNIX for Dummies Questions & Answers

looping through file and creating seperate files

Hi, My first post!! I have a files with header, something like this Header_Row AMC|D1|D2|D2 AAO|D3|D4|D5 AMC|D6|D7|D8 AAO|D9|D10|D11 . . . . . and millions fo records thereafter like this. I want to read the above file in a loop and write the lines having AMC into another... (1 Reply)
Discussion started by: amitbakre
1 Replies

5. Shell Programming and Scripting

looping through files

I am writing a ksh which has to load 7 files(.dat files) from input directory into oracle tables using sql loader. The process has to take each file at a time and once if it is loaded succesfully using sql loader into oracle tables then the process has to pick next file and load it into oracle... (2 Replies)
Discussion started by: vpv0002
2 Replies

6. Shell Programming and Scripting

Looping through 2 files simultaneously

Hi all, I'm having a problem with a script which should ultimately provide a filename by reading a value from file1 and file2 then join together. I'm planning to use a loop/ loops to get the values out of both files and create a single string unfortunately the code currently treats the second... (7 Replies)
Discussion started by: chris01010
7 Replies

7. UNIX for Dummies Questions & Answers

Help in Array looping and creating multiple lines

hi Gurus, I'm a newbie in scripting please check my script if this is correct. I think there's something wrong with it but I;m not sure. I'm trying to create multiple lines using awk from external xml files but i want to add additonal info in the data manually Since i don't knwo how to... (0 Replies)
Discussion started by: sexyTrojan
0 Replies

8. Shell Programming and Scripting

Looping through files...

I posted this in the Solaris forum, but I don't think it's platform specific, so I'm posting it here. Here is the situation. We are a company that has been using a professional publishing system, the software is called "ProType". It runs on Solaris 2.4, however it is no longer supported and we... (6 Replies)
Discussion started by: Fred Goldman
6 Replies

9. Shell Programming and Scripting

Help looping through files, please...

Okay... I've solved one problem. Here's the next. I'm writing a script file that needs to go through a directory and list all files in that directory. I'm using TCL/TK. I figured out how to go through the directory and how to loop through it, but I ran into a little problem. ... (2 Replies)
Discussion started by: kapolani
2 Replies

10. Shell Programming and Scripting

looping files

Hi, I have a file a.lst which lists all files. as a.dat b.dat c.dat I want to process these files mentioned in the list file in a loop. Say I want to display only the first line of all the files a.dat , b.dat, c.dat. How can I go about it? Please help. (5 Replies)
Discussion started by: dharmesht
5 Replies
Login or Register to Ask a Question