Re: Batch Files: Why is it the only the last line of the batch files is executing?

From: Keith Thompson (kst-u_at_mib.org)
Date: 06/03/05


Date: Fri, 03 Jun 2005 03:12:10 GMT


"jmoliver" <jose_oliver@hotmail.com> writes:
> I am trying to write a batch file which changes some file attributes
> using chmod
>
> the batch file is as follows:
>
> chmod u+r, g+r o+r sample1.jsp
> chmod u+r, g+r o+r sample2.jsp
> chmod u+r, g+r o+r sample3.jsp
> chmod u+r, g+r o+r sample4.jsp
>
> When I run the batch file using the "sh" command, the only line which
> is executed is the last one. For the first 3 lines I receive the
> following error:
>
> chmod: Can't access sample1.jsp
> chmod: Can't access sample2.jsp
> chmod: Can't access sample3.jsp
>
> Any ideas on what is going on and how to correct this. I am a UNIX
> newbie.

It *is* executing all four commands. Where do you think the error
messages are coming from?

The chmod command allows multiple operations to be separated by
commas, *not* by spaces. The first command, if it's really as you
posted it, will attempt to enable read-access for the owner ("u+r")
for files named "g+r", "o+r", and "sample1.jsp". Since you didn't get
error messages for "g+r" and "o+r", and since I doubt that you
actually have files by those names, I'm guessing that what you posted
isn't exactly what's in your script.

If you post sample code, *please* cut-and-paste the *exact* code
you're running. Don't expect us to guess which errors are actually in
your script and which are the result of transcription errors.

So, assuming your script actually contains:

chmod u+r,g+r,o+r sample1.jsp
chmod u+r,g+r,o+r sample2.jsp
chmod u+r,g+r,o+r sample3.jsp
chmod u+r,g+r,o+r sample4.jsp

then it should attempt to enable read access for user, group, and
others for the four named files.

If you read the man page for the chmod command, you'll find that the
mode string
    u+r,g+r,o+r
can be simplified to
    ugo+r
which can be further simplified to
    a+r

Now let's take a look at the error messages:

> chmod: Can't access sample1.jsp
> chmod: Can't access sample2.jsp
> chmod: Can't access sample3.jsp

The chmod command is telling you that it can't access the files
sample1.jsp, sample2.jsp, and sample3.jsp.

The rest of us are in no position to guess why this is so -- but you
are. My best guess is that the files don't exist, or that you don't
own them. Try this:

    ls -l sample*.jsp

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.


Relevant Pages