x=foobar: is not an identifier

Everything about Control-M agents installation or setup.
Post Reply
User avatar
rombapa
Nouveau
Nouveau
Posts: 24
Joined: 28 Jun 2011 12:00

x=foobar: is not an identifier

Post by rombapa » 27 Dec 2011 2:36

I have the following script installed on a remote host (agentless node):

Code: Select all

#!/usr/bin/bash

ls -l `which bash`
export x=foobar
The job runs OK when invoked on the command line but in Control-m it abends with the following sysout:
+ /bin/sh -x /tmp/INSTREAM_02522_0003_testskat
+ which bash
+ ls -l /usr/bin/bash
-r-xr-xr-x 1 root bin 732556 May 2 2007 /usr/bin/bash
+ export x=foobar
/tmp/INSTREAM_02522_0003_testskat: x=foobar: is not an identifier
After googling a bit I learned that the "is not an identifier" error is due to sh not supporting the 'export varname=value' syntax. So in my case it seems that the 1st line invoking bash is not considered.

Does anyone have an explanation?

Thanks

User avatar
pmdeshayes
Nouveau
Nouveau
Posts: 23
Joined: 07 Jul 2008 12:00

Post by pmdeshayes » 09 Jan 2012 3:07

Control-M submits jobs using either /bin/sh or */bin/ksh.

If you want to use a bash shell, you'll have to run your script in a bash subshell. You can use KSH directly to make it easier or have your sysadmin link /bin/sh to /usr/bin/bash.

Cheers

User avatar
rombapa
Nouveau
Nouveau
Posts: 24
Joined: 28 Jun 2011 12:00

Post by rombapa » 09 Jan 2012 3:56

Thanks very much for your reply pmdeshayes.

I still have some doubt:

- the same script is scheduled without any problem on another host (this one with its own agent)

- doesn't the first line of my script (#!/usr/bin/bash) force the use of bash?

User avatar
pmdeshayes
Nouveau
Nouveau
Posts: 23
Joined: 07 Jul 2008 12:00

Post by pmdeshayes » 09 Jan 2012 7:00

The first line is called a 'shebang'. What you specify as a shebang is used in certain occasions. Here's a little demonstration which is better than words:

$ id
uid=1115(ctmsvadm) gid=500(controlm)

$ which bash
/usr/bin/bash

$ ls -ld /usr/bin/bash
-r-xr-xr-x 1 root bin 732556 May 2 2007 /usr/bin/bash

Note: This is not a symlink as you can see

$ pwd
/tmp

$ cat shebang.sh
#!/usr/bin/bash
_pid=$$
echo "PID: ${_pid}"
ptree ${_pid}
export x=foobar

# Method #1
$ shebang.sh
PID: 3491
4749 /usr/lib/ssh/sshd
16226 /usr/lib/ssh/sshd
16238 /usr/lib/ssh/sshd
22028 ksh -o vi
3491 /usr/bin/bash shebang.sh
3493 ptree 3491

# Method #2
$ /bin/sh shebang.sh
PID: 22793
4749 /usr/lib/ssh/sshd
16226 /usr/lib/ssh/sshd
16238 /usr/lib/ssh/sshd
22028 ksh -o vi
22793 /bin/sh shebang.sh
22796 ptree 22793
shebang.sh: x=foobar: is not an identifier

As you can see, when launched without specifying the shell (Method #1), the shebang is taken into account and the content of the script is ran within a subshell. When using Method #2 (aka. as does Control-M/Agent), the shell is ran using the shell launching the script.

Cheers

User avatar
rombapa
Nouveau
Nouveau
Posts: 24
Joined: 28 Jun 2011 12:00

Post by rombapa » 11 Jan 2012 2:40

Thanks for the demonstration pmdeshayes. That clarifies things!

Post Reply