Sh: ...: is not an identifier when trying to invoke shell scripts using plink

Below is my shell script, which 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 use PLINK to execute a shell script as shown 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 error below that I always get whenever I try to run as shown above.

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

Is there something wrong with my shell script? or some trailing spaces? I can’t figure it out. I run PLINK from the machine window

+4
source share
2 answers

The prefix sh: in the error message indicates that the script is running sh , not bash .

bash allows you to combine the configuration of a variable and export it into one command:

 export foo=bar 

sh, or at least some older versions, require that these two actions be separated:

 foo=bar ; export foo 

A version of sh that does not recognize the export foo=bar syntax will interpret the string foo=bar as a variable name (and illegal because it is not an identifier).

Prepare the script for bash or change this:

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

:

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

In this regard, since you mean $HIVE_OPTS at the very beginning of your script, it is almost certainly already exported, so you can simply abandon export .

(You also need to avoid any other bash-specific functions.)

So why does the system call a shell with sh? The syntax #!/bin/bash specific to Unix-like systems. Windows usually decides how to execute the script based on the file extension; obviously, your system is configured to access *.sh files with sh. (You can configure your system using the folder options to call *.sh files using bash, but this can cause other problems.)

+13
source

I think the -m option for plink is for reading commands to execute on a remote computer from a local file. If my comment about line termination does not work, try

 plink uname@MachineB test.sh 

Make sure test.sh executable by running

 chmod +x test.sh 

on MachineB.

+2
source

All Articles