[X-Unix] Loop structure syntax question
Mac Daddy
macdaddee at gmail.com
Wed Nov 23 13:07:32 PST 2005
I have a script running on several macs, a small part of which fails.
---------------------------------- snippet
f# Add Admin users first.
foreach login ( `cat ./logins_Y.txt` )
dscl . merge /groups/cq users "$login"@<mydomain.com>
end
# Add normal Users next
foreach login ( `cat ./logins_A.txt` )
dscl . merge /groups/cq users "$login"@<mydomain.com>
end
-------------------------- end snippet
This reads two text files on disk and then adds each name read into a
special group in the Netinfo db.
It's part of a larger script, and the larger script fails somewhere
in the second loop reading "logins_A.txt", leaving the group only
partially filled with usernames. VERY BAD, as the group is used for
authentication on the machine.
This thing is, this script NEVER fails when run by hand! Only when
run in cron.
I have the script set to run in #!/bin/csh because this 'foreach'
loop structure above fails if I run it under /bin/sh or /bin/bash and
the code was given to me by someone else who uses csh on Solaris.
I think it's /bin/csh that's the problem, since when invoked by hand,
I'm using /bin/bash, which in turn is invoking this script that runs
under /bin/csh. There's no problem then. It's the only thing I can
think of. I even have a SECOND script in the cron set to run under #!/
bin/sh which checks to see if the first one fails, notifies me if it
does, then re-runs the first script as an attempt to correct the
situation before I can check. This check script works every single
time, further making me think /bin/csh by itself is the problem.
ANYWAY, I'd gladly have the script run under /bin/sh or /bin/bash IF
I just knew the proper syntax for the 'foreach' structure under one
of the other shells, but I can't figure it out and haven't found it yet.
Can somebody help me out with the proper syntax for one of the other
shells please?
More information about the X-Unix
mailing list