1834149 Members
3848 Online
110064 Solutions
New Discussion

ksh script problem

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

ksh script problem

HI,

I've inserted .ksh file for the purpose of changing the numeric user ids of several users in a filesystem.

Problem is, it contains errors listed below whenever I try executing it:
ChangeUID.ksh[3]: =: not found
ChangeUID.ksh[7]: =: not found
Test
ChangeUID.ksh[17]: =: not found
uname =
ypmatch: 1831-150 Cannot match key passwd.byname in map file
Reason: no such map file in server's domain.
ChangeUID.ksh[20]: =: not found
uid =
ChangeUID.ksh[23]: =: not found
file =
not within specified range
Test
...... and the same block of errors just keeps repeating itself for other entries in the text file fileList.txt.

I've tried running the exact ypmatch portion over the console, & it works OK, but not during execution of the script.

Can anyone help?
Thanks

5 REPLIES 5
S.K. Chan
Honored Contributor

Re: ksh script problem

It looks like a lot of basics are not correct in your script. First ..

if ["$?" !="0"]

should be

if (($? != 0))

since you're evaluation numbers you can use "((". Then your variable assignments are all wrong ..

$uname = `echo $line |awk '{print $3}'`

should be (use some other name because uname is a command but that's besides the point, if you want to assign a value to a variable don;t use $ in that variable until you want to call it later)

username=`echo $line | awk '{print $3}'`

Next ..

$mypasswdfile = `ypmatch $3 passwd.byname > passwd file`

..here you are redirecting output from ypmatch to a file "passwd" and "file" ? And at the same time you want to assign file filename to a variable ..? Not sure what you're trying to do here. I think this is what you actually wanted ?

ypmatch $3 passwd.byname > passwd-file
mypasswdfile=passwd-file

Then ..

$uid = `id $uname`

same argument ... no "$" sign ..

UID=`id $username`

and it goes on ..

It would be better if you can show the content of "fileList.txt" and describe again what you want the script to do and if it's not me, someone else will come up with a workable script for you.
Steven Sim Kok Leong
Honored Contributor

Re: ksh script problem

Hi,

Two major syntax mistakes (I am not looking at the semantics):

1) you should not but a dollar sign for the variable name in the assignment. That is perl syntax, not ksh syntax. Example:

Instead of:

$allowedDir = /usr/home/oper1/cleaw/UID

It should be:

allowedDir = /usr/home/oper1/cleaw/UID

2) There must be a space between then starting [ and ", a space between = and " and a space between the ending " and ]. Example:

Instead of:

if ["$?" !="0"]

It should be:

if [ "$?" != "0" ]

Once this is fixed, the syntax errors listed on lines 3, 7, 17, 20, 23 will be fixed.

Hope this helps. Regards.

Steven Sim Kok Leong
Chern Jian Leaw
Regular Advisor

Re: ksh script problem

Hi Steven & SK,

I forgot to include the file "fileList.txt"
It is an output from 'ls -l'.

I'm including it in this reply message.

Trond Haugen
Honored Contributor

Re: ksh script problem

As it seems the problems have already been identifyed I would just like to point out that when debugging scripts, it's oftern verry usefull to insert 'set -x' at the start of the script. Or run it with 'sh -x myscript'. That way you will see what the script executes and evaluates.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Ceesjan van Hattum
Esteemed Contributor
Solution

Re: ksh script problem

One:
if ["$?" !="0"] should be:
if [ "$?" != "0" ] (use spaces)

Two:
$uname = `echo ..` should be:
uname=`echo ..` (no $ in ksh)
(and other cases...)

So.. take care of your spaces and $-signs in Ksh.

In short:
var=`uname -a`; echo $var
and not:
var = `uname -a`; echo $var
and not:
$var = `uname -a; echo $var

Regards,
Ceesjan