-1

there's a command to start up a service which is su -s /bin/bash nuance -c '$JAVA_HOME/bin/java -Dlog4j.configurationFile=$NLPS_HOME/config/log4j2.xml -jar $NLPS_HOME/lib/nlps.jar --spring.config.location=$NLPS_HOME/config/,$NUANCE_DATA_DIR/system/config/User-nlps01.properties watcher.RestartOnFailure=FALSE watcher.SendAlarmsToWatcher=FALSE > /dev/null 2>&1 &' I want this command to run at startup in my rhel 7 linux. So I tried crontab, which is @reboot sh /execute/nlp.sh

But it doesn't work, I don't know why. Please tell me what I'm doing wrong I'm so stuck Inside nlp.sh:

#!/bin/bash
/bin/su -s /bin/bash nuance -c '$JAVA_HOME/bin/java -Dlog4j.configurationFile=$NLPS_HOME/config/log4j2.xml -jar $NLPS_HOME/lib/nlps.jar --spring.config.location=$NLPS_HOME/config/,$NUANCE_DATA_DIR/system/config/User-nlps01.properties  watcher.RestartOnFailure=FALSE watcher.SendAlarmsToWatcher=FALSE > /dev/null 2>&1 &'

2 Answers2

1

You need to define $JAVA_HOME,$NLPS_HOME and $NUANCE_DATA_DIR environment variables are needed to be defined and exported before the execution of the script.

export JAVA_HOME=/path/to/java/home
export NUANCE_DATA_DIR=/path/to/nuance/dir
export NLPS_HOME=/path/to/npls/home
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
  • That actually makes sense and I did put the environment variables but still no luck, tired even giving full paths. I don't know why the command works executing directly and straight of a shell file but doesn't work on crontab, systemd service or even /etc/init.d/ – zackryderrrr Oct 08 '20 at 18:41
  • there might be several reasons. you can check cron logs. for ubuntu ` grep CRON /var/log/syslog` – Derviş Kayımbaşıoğlu Oct 08 '20 at 18:43
0

You have to use double quotes to interpolate variables. Single quotes won't interpolate anything, but double quotes will.

/bin/su -s /bin/bash nuance -c "$JAVA_HOME/bin/java -Dlog4j.configurationFile=$NLPS_HOME/config/log4j2.xml -jar $NLPS_HOME/lib/nlps.jar --spring.config.location=$NLPS_HOME/config/,$NUANCE_DATA_DIR/system/config/User-nlps01.properties  watcher.RestartOnFailure=FALSE watcher.SendAlarmsToWatcher=FALSE > /dev/null 2>&1 &"

From Bash manual:

3.1.2.2 Single Quotes

Enclosing characters in single quotes (') preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

3.1.2.3 Double Quotes

Enclosing characters in double quotes (") preserves the literal value of all characters within the quotes, with the exception of $, `, \, and, when history expansion is enabled, !. The characters $ and ` retain their special meaning within double quotes (see Shell Expansions). The backslash retains its special meaning only when followed by one of the following characters: $, `, ", \, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ! appearing in double quotes is escaped using a backslash. The backslash preceding the ! is not removed.

The special parameters * and @ have special meaning when in double quotes (see Shell Parameter Expansion).

1218985
  • 7,531
  • 2
  • 25
  • 31
  • Yes I tried putting double quotes. Is there any way I could execute this command at the startup or even call it by any shell? I have no clue how to – zackryderrrr Oct 08 '20 at 18:43