5

Below is my shell script that I am trying to execute using PLINK on MachineB from MachineA(Windows Machine).

#!/bin/bash
export HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"
hive -S -e 'SELECT count(*) from testingtable1' > attachment22.txt

I am using plink to execute the shell script like below,

C:\PLINK>plink uname@MachineB -m test.sh
Using keyboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Your Kerberos password will expire in 73 days.

And this is the below error I always get whenever I try to run like above.

sh: HIVE_OPTS= -hiveconf mapred.job.queue.name=hdmi-technology: is not 
an identifier

Something wrong with my shell script? or some trailing spaces? I am not able to figure it out. I am running PLINK from windows machine

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
arsenal
  • 23,366
  • 85
  • 225
  • 331
  • If you created `test.sh` on your local Windows machine, you'll have to make sure the file has Unix, not Windows, line endings for it to run properly on the remote Unix host. – chepner Jul 27 '12 at 18:20
  • Thanks chepner. How can I make sure `test.sh` has unix file endings? I am using `Notepad++` to create the test.sh file and in that there is an option to create it in unix format and I did the same way. – arsenal Jul 27 '12 at 18:22
  • Hm. On the remote machine, you can try `file test.sh`, and make sure it doesn't say anything about CRLF line terminators. – chepner Jul 27 '12 at 18:27
  • 1
    I've removed the update from your question. If you still want to ask about it, please post a new question (see this question's [edit history](http://stackoverflow.com/posts/11693405/revisions). – Keith Thompson Feb 26 '14 at 00:04

2 Answers2

15

The sh: prefix on the error message indicates that the script is being executed by sh, not bash.

bash lets you combine setting a variable and exporting it into a single command:

export foo=bar

sh, or at least some older versions of it, require these two actions to be separated:

foo=bar ; export foo

A version of sh that doesn't recognize the export foo=bar syntax will interpret the string foo=bar as a variable name (and an illegal one, since it isn't an identifier).

Either arrange for the script to be executed by bash, or change this:

export HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"

to this:

HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"
export HIVE_OPTS

For that matter, since you're referring to $HIVE_OPTS at the very beginning of your script, it's almost certainly already exported, so you could just drop the export.

(You'll also need to avoid any other bash-specific features.)

So why is the system invoking the shell with sh? The #!/bin/bash syntax is specific to Unix-like systems. Windows generally decides how to execute a script based on the file extension; apparently your system is configured to invoke *.sh files using sh. (You could configure your system, using Folder Options, to invoke *.sh files using bash, but that might introduce other problems.)

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • Thanks Keith, that fixed my previous problem, but I am getting new errors, I have updated my question with my updated shell script. it will be great if you can give some more suggestions on that. – arsenal Jul 27 '12 at 18:57
  • 2
    You should open a new question for this, rather than continue here. – chepner Jul 27 '12 at 19:11
2

I think the -m option to plink is for reading commands to execute on the remote machine from a local file. If my comment about line endings doesn't work, try

plink uname@MachineB test.sh

Make sure test.sh is executable by running

chmod +x test.sh

on MachineB.

chepner
  • 497,756
  • 71
  • 530
  • 681