Jump to content

Recommended Posts

Hi, I am new to linux and was trying my first experience using cygwin on Windows 7. I am trying to run the following simple script named parsescript3 in the home directory and keeps getting the error 'syntax error near unexpected token `(''. Can anyone please help and let me know what is exactly wrong with the syntax? 

 

~/bin/parsescript3 content

#!/bin/bash

FOR /F "TOKENS=1,2 DELIMS=," %%A IN ("serverA,D") DO @ECHO %%A %%B

 

Execution and output on cygwin64:

~/bin

$ ./parsescript3

./parsescript3: line 3: syntax error near unexpected token `('

./parsescript3: line 3: `FOR /F "TOKENS=1,2 DELIMS=," %%A IN ("serverA,D") DO @ECHO %%A %%B'

Hi requinix, ok, in that case what should be the correct syntax for linux then?

I actually got the script from the following site http://www.systemtoolbox.com/article.php?articles_id=1023 with the full script as given below. The purpose of the script was to iterate through the server list file and maps each of the server drives that was indicated and takes a snapshot of the df information as it stands at that time. It then parses out the number of gigs used and appends it to a file named relative to server and drive letter. Unfortunately I can't even get past the 1st line. I thought it has to do with the list file so I just tried a simplified version with just the text strings but it seems it still didn't work. Please help. Your advise is much appreciated. Thanks!

 

for /f "tokens=1,2 delims= " %%A in (drives.lst) do (

echo %%A %%B

net use y: /del < y.ans

net use y: \\%%A\%%B$

df -h | findstr -i y: > temp.txt

type temp.txt | cut -f2 -d: | cut -f2 -dG > temp2.txt

 

for /f %%Q in (temp2.txt) do (

echo %%Q >> %%A-%%B.txt

)

del temp.txt

del temp2.txt

)

You don't actually run that script from a Cygwin shell. Read what he actually wrote:

To set up Dashboarding in Excel, we first have to collect data. Microsoft tools for disk space reporting from command line is either lacking in information or is difficult to parse. To this end, I looked to use the df command found in Linux/UNIX. This gives the info I wanted and runs easily in Windows. Simply go to http://www.cygwin.com/ to get the Cygwin version of the program. You can either install Cygwin completely locally or put it in your executable path (under My Computer > Properties > Advanced > Environmental Variables > PATH variable) or you can just download and pull out the Cygwin*.dll and the df executable. Since it consumes less space, I chose the latter option.

He grabbed the df executable and put that in an accessible place. The commands there go in a regular Windows batch file, not a bash script.

 

But ugh, that whole thing makes me feel dirty just looking at it. Disk usage information should be calculated using something like PowerShell and some WMI queries against the hosting servers.

Oh, ok. Unfortunately I am unable to get any response from the original site to clarify on the stuff in the article. I just wanted to have a dashboard tool to do the same thing, i.e. show all the volume utilization for various servers on a nice dashboard.

 

I did try putting the whole script in .bat batch file but still not getting response from the script. I guess I will have to look around for a better solution.

 

Thanks again for your responses.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.