For loop - unexpected token `do


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For loop - unexpected token `do
# 1  
Old 08-28-2015
For loop - unexpected token `do

My requirement is to search for current date-1 .log files in /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs folder and write the file name to filenames.txt

When I ran the script below, I got error as
Code:
syntax error near unexpected token `do

I'm not sure what is wrong in my code. I seek some help to achieve this task effeftively

Code:
#!/bin/sh
for i in /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/"SASApp_STPServer_"$(date +%Y-%m-%d --date "1 day ago")"_tmptcmsaslva2_"*".log"
do
  echo $i
done

echo $i >> output_file.txt


Last edited by rbatte1; 09-07-2015 at 09:10 AM.. Reason: Added CODE tags for error message
# 2  
Old 08-28-2015
Hello Ram_kumar_BE,

Could you please try following and let me know if this helps.
Code:
#!/bin/sh
for i in "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_"$(date +%Y-%m-%d --date "1 day ago")"_tmptcmsaslva2_"*".log"
do
    echo $i
done

If you are happy with above command's result then please change echo $ito echo $i >> output_file.txt

Thanks,
R. Singh
# 3  
Old 08-28-2015
The way /bin/sh processes command substitution and the way date processes --date varies considerably from operating system to operating system.

What operating system are you using?

You said your output filename is filenames.txt, but nothing in your script writes anything to a file with that name???
# 4  
Old 08-28-2015
Hi Ravinder,

Still I'm getting the same error.

---------- Post updated at 01:14 AM ---------- Previous update was at 01:11 AM ----------

I'm using SSH secure client to connect the terminal. Bash version is 4.1.3.

My output filename is output_file.txt.
# 5  
Old 08-28-2015
I repeat: "What operating system are you using?" And, since you're using ssh, show us the exact ssh command you're executing and tell us what operating system you're using on the system where you're running ssh and what operating system you're using on the system you're connecting to with ssh.
# 6  
Old 08-28-2015
I will execute the script in command prompt like
Code:
sh list_file.sh

I use SSH secure client which is a windows application and then select the server which I need to connect by supplying username and password.

Then I will navigate to 'New terminal window' from the tool bar in SSH secure client and then I will go to the directories to develop\run a shell script.

If you need any further information about my environment, kindly advise me the steps which you want me to look for.

Thanks.

---------- Post updated at 02:27 AM ---------- Previous update was at 01:43 AM ----------

My operating system is LINUX
# 7  
Old 08-28-2015
After you connect to the server and open a new terminal window, show us the output from the following commands typed into that terminal window:
Code:
/bin/sh --version
uname -a
type bash date sh
ls -l /bin/bash /bin/date /bin/sh

PS... And what output do you get from the command:
Code:
date +%Y-%m-%d --date "1 day ago"


Last edited by Don Cragun; 08-28-2015 at 04:32 AM.. Reason: Add PS.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Syntax error near unexpected token `('

detect_mouse_mvt.sh /home/andy/bin/detect_mouse_mvt.sh: line 4: syntax error near unexpected token `(' /home/andy/bin/detect_mouse_mvt.sh: line 4: `fh = file('/dev/input/mice')' #!/bin/bash # # fh = file('/dev/input/mice') while True: fh.read(3) print 'Mouse... (15 Replies)
Discussion started by: drew77
15 Replies

2. UNIX for Beginners Questions & Answers

Syntax error near unexpected token 'do'

Hello all, Please i have this command i used to zip different files in differents directory, but i have an error. Note that when i run the command in one directory it works fine. /X5/WORK/BGH/INV/REG/pdf/SEND/BGH12523/1/*.fo /X5/WORK/BGH/INV/REG/pdf/SEND/BGH24523/1/*.fo... (3 Replies)
Discussion started by: gillesi
3 Replies

3. Shell Programming and Scripting

Syntax error near unexpected token '('

I tried to execute the code but I got this error ./Array.c: line 9: syntax error near unexpected token '(' ./Array.c: line 9: ' nvals = get_data(a,MAXARRAY);' and #include<stdio.h> #define MAXARRAY 1000 main() { int a, nvals; nvals =... (7 Replies)
Discussion started by: sgradywhite
7 Replies

4. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hi, I am trying to read the session log through script. But it keeps showing me some error near. I have tried everything. Even tried converting the script using sed command to remove the hidden characters(\r).But nothing seems to be working.Below is the script : #!/bin/bash cd... (6 Replies)
Discussion started by: Aryan12345
6 Replies

5. Shell Programming and Scripting

syntax error near unexpected token `='

Hi all, This is a script which converts hex to bin. However am finding an error while executing syntax error near unexpected token `=' `($hexfile, $binfile) = @ARGV;' I am running using ./fil.pl <hexfile> <binfile> ################################################### # # this script... (3 Replies)
Discussion started by: jaango123
3 Replies

6. Shell Programming and Scripting

Unexpected Token Error `;;'

Hello all, Im having an Issue with my script for switch statement , can someone let me know where do i need to correct it. 7 ##******************************************************************************************************* 8 ## ********** FUNCTION USAGE *********** ... (13 Replies)
Discussion started by: raghunsi
13 Replies

7. Shell Programming and Scripting

Syntax error near unexpected token `done'

Hi all, Here is a simple script that is working in one server and is giving a syntax error in other server. Can somebody help me ? #!/bin/bash # ftp files done < $file errors: I tried..with no success: if ; then (21 Replies)
Discussion started by: Lenora2009
21 Replies

8. Shell Programming and Scripting

Syntax error near unexpected token `('

Guys , This is an output of my script errored out for "Syntax error near unexpected token `(' " Can someone tell me whats wrong with my script. Below is my original script pasted. #!/bin/bash Script Creation Date 01/21/2010 Author baraghun ... (7 Replies)
Discussion started by: raghunsi
7 Replies

9. Shell Programming and Scripting

sh syntax error unexpected token done

I'm getting the following error: line 21: syntax error near unexpected token `done` line 21: `done` and I haven't been able to figure out why. Here is my code #!/bin/sh if ; then echo 'Usage: rename getexp/replStr ' exit 0 fi arg = $1 shift while ; do (5 Replies)
Discussion started by: NullPointer
5 Replies

10. Shell Programming and Scripting

While loop error: Unexpected token done

I have tried to implement a while loop into the code but upon running the following code i am getting the errors: ./Assigntest: line 42: syntax error near unexpected token `done' ./Assigntest: line 42: `done' The code is as follows: #!/bin/bash #Filename: Assignment Author: Luke... (9 Replies)
Discussion started by: warlock129
9 Replies
Login or Register to Ask a Question