cumulocity's rasberrypi's "c8y-agent.sh" file not working - java

I am trying to connect my cumulocity-rpi-agent to cumulocity so that I can have two options either accept or cancel. But this options will be available only when i execute sh c8y-agent-debug.sh this file using sh command. I followed below steps
1) wget http://resources.cumulocity.com/examples/cumulocity-rpi-agent-latest.deb
2) sudo dpkg -i cumulocity-rpi-agent-latest.deb
And:
login as: pi
pi#raspberrypi.mshome.net's password:
...
pi#raspberrypi:~ $ cd /usr/share/
pi#raspberrypi:/usr/share $ cd cu
cumulocity-rpi-agent/ cups/
pi#raspberrypi:/usr/share $ cd cumulocity-rpi-agent/
pi#raspberrypi:/usr/share/cumulocity-rpi-agent $ sh c8y-agent.sh
^C
pi#raspberrypi:/usr/share/cumulocity-rpi-agent $ sudo nano
pi#raspberrypi:/usr/share/cumulocity-rpi-agent
And:
#!/bin/sh
(
while true
do
echo "Running the Cumulocity Linux Agent..."
java -cp 'cfg/*:lib/*' -Dlogback.configurationFile=cfg/logback.xml c8y.lx.age$
sleep 1
done
) 2>&1 | logger
this is c8y-agent-debug.sh script I execute this file using sh c8y-agent-debug.sh or bash c8y-agent-debug.sh but executing the file not event echo statement.
Do i need to set anything related to java. Java is already installed. Is there any additional setting required for that java -cp command. Java is installed on /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/ on this path. This is on linux. javac and java commands are working fine

Related

getting the error "TERM environment variable not set" when running a bash script from Java process builder [duplicate]

I have a file.sh with this, when run show : TERM environment variable not set.
smbmount //172.16.44.9/APPS/Interfas/HERRAM/sc5 /mnt/siscont5 -o
iocharset=utf8,username=backup,password=backup2011,r
if [ -f /mnt/siscont5/HER.TXT ]; then
echo "No puedo actualizar ahora"
umount /mnt/siscont5
else
if [ ! -f /home/emni/siscont5/S5.TXT ]; then
echo "Puedo actualizar... "
touch /home/emni/siscont5/HER.TXT
touch /mnt/siscont5/SC5.TXT
mv -f /home/emni/siscont5/CCORPOSD.DBF /mnt/siscont5
mv -f /home/emni/siscont5/CCTRASD.DBF /mnt/siscont5
rm /mnt/siscont5/SC5.TXT
rm /home/emni/siscont5/HER.TXT
echo "La actualizacion ha sido realizada..."
else
echo "No puedo actualizar ahora: Interfaz exportando..."
fi
fi
umount /mnt/siscont5
echo "/mnt/siscont5 desmontada..."
You can see if it's really not set. Run the command set | grep TERM.
If not, you can set it like that:
export TERM=xterm
Using a terminal command i.e. "clear", in a script called from cron (no terminal) will trigger this error message. In your particular script, the smbmount command expects a terminal in which case the work-arounds above are appropriate.
You've answered the question with this statement:
Cron calls this .sh every 2 minutes
Cron does not run in a terminal, so why would you expect one to be set?
The most common reason for getting this error message is because the script attempts to source the user's .profile which does not check that it's running in a terminal before doing something tty related. Workarounds include using a shebang line like:
#!/bin/bash -p
Which causes the sourcing of system-level profile scripts which (one hopes) does not attempt to do anything too silly and will have guards around code that depends on being run from a terminal.
If this is the entirety of the script, then the TERM error is coming from something other than the plain content of the script.
You can replace :
export TERM=xterm
with :
export TERM=linux
It works even in kernel with virgin system.
SOLVED: On Debian 10 by adding "EXPORT TERM=xterm" on the Script executed by CRONTAB (root) but executed as www-data.
$ crontab -e
*/15 * * * * /bin/su - www-data -s /bin/bash -c '/usr/local/bin/todos.sh'
FILE=/usr/local/bin/todos.sh
#!/bin/bash -p
export TERM=xterm && cd /var/www/dokuwiki/data/pages && clear && grep -r -h '|(TO-DO)' > /var/www/todos.txt && chmod 664 /var/www/todos.txt && chown www-data:www-data /var/www/todos.txt
If you are using the Docker PowerShell image set the environment variable for the terminal like this with the -e flag
docker run -i -e "TERM=xterm" mcr.microsoft.com/powershell

not able to execute next statement in a shell script after running a java jar app using nohup

Not able to execute other instruction after if I am running a java jar file (which is present on another host) from my shell script.I tried using nohup but still not able to exit.
following is my script
#!/usr/bin/env bash
sshpass -p "${array[1]}" ssh -oStrictHostKeyChecking=no ${array[0]}#${array[2]} "cd ${array[3]} && echo -ne '\n' | nohup java -jar myapp.jar";
#some other instructions
echo "next statement"
already tried Scripts with nohup inside don't exit correctly but it doesn't worked.
sshpass -p pass ssh -o StrictHostKeyChecking=no xyz#hostname 'cd dir; nohup java -jar myapp.jar'
Try this with replacing the values appropriately

Install Java7 on Ubuntu 16.04 through bash script

I have below function java_install written in a bash script to install java on Linux box, to which I pass jdk-1.7.0_80-linux-x64.tgz as JAVA_PACKAGE.
Now what is happening is java gets installed and works fine only within the script. Once I come out of this script, none of the java functionalities work, not even java -version. Could someone please help me on what I might be missing here? Basically, I just want java to be installed permanently on this box once this script is executed.
java_install() {
local JAVA_PACKAGE=$1
local TMPDIR=/tmp/quickstart
local TARGET=/usr/share
if [ -n "$JAVA_PACKAGE" ] && [ -f "$JAVA_PACKAGE" ]; then
rm -rf $TMPDIR
mkdir -p $TMPDIR
cp $JAVA_PACKAGE $TMPDIR
( cd $TMPDIR && tar fxz $JAVA_PACKAGE && rm $JAVA_PACKAGE )
local JAVA_BASENAME=$(ls -1 $TMPDIR)
mkdir -p $TARGET
if [ -d "$TARGET/$JAVA_BASENAME" ]; then
echo "# Java already installed at $TARGET/$JAVA_BASENAME"
log_info "Java already installed at $TARGET/$JAVA_BASENAME"
else
echo "# Java now installed at $TARGET/$JAVA_BASENAME"
log_info "Java now installed at $TARGET/$JAVA_BASENAME"
mv $TMPDIR/$JAVA_BASENAME $TARGET
fi
rm -rf $TMPDIR
# now create a script to export these settings
export JAVA_HOME=$TARGET/$JAVA_BASENAME
export PATH=$JAVA_HOME/bin:$PATH
else
echo "# cannot find java package to install"
log_error "cannot find java package to install"
fi
}
Use update alternatives within your script to make your java installation available:
sudo update-alternatives --install "/usr/bin/java" "java" "path to you java executable" 1
More information on this topic can be found here: How to use the command update-alternatives --config java.
Alternatively you can write the export commands for JAVA HOME and PATH to your .bashrc from within your script (if using bash). This way the modified variables are available in the bash shell.

System.exit() status code not working when compiled into native app

I've created a JavaFX 2 app of which I'm adding a command-line mode (so that it can be run in a batch mode from nightly scripts). For this to be effective, I want to set the exit status to indicate errors. I'm doing this with this code:
if (errorOccurred) {
Platform.exit();
System.exit(exitCode);
}
This works fine when I run it from the IntelliJ, and I see this in the Console window:
Process finished with exit code 255
When I run the jar from the command line it also works:
$ java <snip-lots-of-arguments> cool_app.Main
$ echo $?
255
But after I use javapackager to turn the jar into a native application, it stops working:
$ javapackager -deploy -native -outdir out -outfile "cool_app.app" -srcfiles cool_app.jar -appclass cool_app.Main -name "cool_app" -title "cool_app"
$ open out/cool_app.app
$ echo $?
0
I'm using JDK 8u40 on MacOS 10.10.4.
Is there something I'm missing? Or a bug in javapackager?

Jar not running

So I created a script the the following commands
#! /usr/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
JAVA=/usr/bin/java
MY_SERVER=/home/user/Desktop/Hello.jar
USER=user
/bin/su - $USER -c "$JAVA -jar $MY_SERVER &"
And I saved it in
etc/init.d/
And then ran the following command in terminal
sudo update-rc.d java_server_launch.sh defaults
I have a program located at
/home/user/Desktop/
And it is called Hello.jar and it works fine when I run it. When I restart my computer for some reason the program (Hello.jar) does not execute. What am I doing wrong?
I'm doing exactly what the answer here says.
You need to replace Hello.jar with $MY_SERVER in the last line of your bash script. That's because your current working directory isn't /home/user/Desktop
Edit: Try replacing the last line of code with this:
/bin/su $USER -c "$JAVA -jar $MY_SERVER &"
if you're running on Ubuntu you should check out upstart
see how simple it is to run jar https://stackoverflow.com/a/12102542/41576

Categories

Resources