简体   繁体   中英

sh: …: is not an identifier when trying to invoke shell scripts using plink

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

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.)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM