Running a sh file on Synology - nas

I’ve a Synology NAS box running with an ARM71. I installed a Blynk server which is running only when I’m connected via Putty. When I disconnect myself from the NAS server, Blynk stops running. To ensure the Blynk server is running, a watchdog.sh is created to be executed every 5 minutes via cron.
My Blynk files are stored in a blynk folder at volume1/blynk/
When the following watchdog file is executed, a command not found error is generated. Its function is to check if the blynk server is running and if not, execute it.
I’m not keen in Linux so any help is appreciated.
TIA
#!/bin/sh
#
#Watchdog script for blynk server
#
stat=`/bin/ps -aux | /bin/grep -c "blynk"`
server="server-0.29.6.jar"
if [ $stat -lt "2" ]; then
/usr/local/bin/java -Djava.net.preferIPv4Stack=true -jar /volume1/blynk/$server -serverConfig /volume1/blynk/server.properties -dataFolder /volume1/blynk/ &
fi

Related

code deployment via zipped file in jenkins

I am new to Jenkins and still taking baby steps to learn it. What I have could be very simple to some people but I couldn't find a straightforward way to do it. I simply want to take source code in a zipped file format and do the following:
copy to remote server in a certain directoy
delete the old code
unzip the new code
delete the zipped file
finally start apache web server
I have installed plugins like ssh2, ssh-copy, remote commands, etc but still cannot achieve what I am looking in to do. Any help would greatly appreciated it.
I have a Spring project and build it to get a .war file by Jenkins.
The following shell commands show how to copy the .war to a remote server and to run it on Tomcat.
remote_host=192.168.1.2
tomcat_home=/x/y
# stop web server
ssh root#${remote_host} "sh /root/stop.sh" || echo "something wrong ignored!"
# copy to remote server in a certain directoy
scp $WORKSPACE/build/libs/myapp-test.war root#${remote_host}:$tomcat_home/webapps/myapp.war
# delete the old code
ssh root#${remote_host} "rm -rf $tomcat_home/webapps/*"
# unzip the new code
ssh root#${remote_host} "unzip -o $tomcat_home/webapps/myapp.war -d $tomcat_home/webapps/myapp"
# delete the zipped file
ssh root#${remote_host} "rm -rf $tomcat_home/webapps/myapp.war"
# finally start apache web server
ssh root#${remote_host} "sh $tomcat_home/bin/startup.sh"
In my case, I put the commands in a Jenkins job and at the section: Build -- Execute shell -- Command

VSCode Remote-SSH Cannot Connect

I'm trying to use the Remote-SSH extension to edit files on a Linux server from my Windows 10 development machine. Normally, I log into the server using VNC and edit files locally OR I use WinSCP to pull the files to my development machine and copy them back over when done. The Remote-SSH extension seems to be the answer to this inefficiency.
I can SSH just fine using Putty or using Git Bash, but Remote-SSH fails to connect. There's some hints in the error message, but I'm not sure how to interpret them.
Here is my SSH config file (redacted) and the error I receive (redacted):
Config:
Host xxx.yy.gov
HostName xxx.yy.gov
User myusername
Error Message:
[08:44:36.981] remote-ssh#0.47.2
[08:44:36.981] win32 x64
[08:44:36.983] SSH Resolver called for "ssh-remote+xxx.yy.gov", attempt 1
[08:44:36.983] SSH Resolver called for host: xxx.yy.gov
[08:44:36.983] Setting up SSH remote "xxx.yy.gov"
[08:44:37.030] Using commit id "[some-string-of-numbers]" and quality "stable" for server
[08:44:37.033] Testing ssh with ssh -V
[08:44:37.101] ssh exited with code: 0
[08:44:37.101] Got stderr from ssh: OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4
[08:44:37.105] Running script with connection command: ssh -T -D 52772 xxx.yy.gov bash
[08:44:37.107] Install and start server if needed
[08:44:37.111] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[08:44:37.264] >
[08:44:37.264] Got some output, clearing connection timeout
[08:44:37.611] > myusername#xxx.yy.gov's password:
[08:44:37.612] Showing password prompt
[08:44:44.709] Got password response
[08:44:44.709] "install" wrote data to terminal: "**************"
[08:44:44.730] >
>
[08:44:45.102] > bash: bash: command not found
>
[08:44:45.476] "install" terminal command done
[08:44:45.476] Install terminal quit with output: bash: bash: command not found
[08:44:45.476] Received install output: bash: bash: command not found
[08:44:45.477] Stopped parsing output early. Remaining text: bash: bash: command not found
[08:44:45.477] Failed to parse remote port from server output
[08:44:45.477] Resolver error:
[08:44:45.480] TELEMETRY: {"eventName":"resolver","properties":{"outcome":"failure","reason":"UnparsableOutput",
"askedPw":"1","askedPassphrase":"0","asked2fa":"0","askedHostKey":"0","gotUnrecognizedPrompt":"0",
"remoteInConfigFile":"1"},"measures":{"resolveAttempts":1,"retries":1}}
[08:44:45.482] ------
VSCode Remote-SSH error
There are there are three ways you can try. I know the problem is annoying.
Check your vscode is local window or remote window. Then, check
remote-ssh setting. (Make sure Local Server Download is auto && Use
local Server is marked.).
Remote SSH:Path . you can switch to local ssh or git/ssh
Try to update or revert remote-ssh.(Version 0.50 can connect to server host stably, I found. This one is very useful.
Maybe you just select 'Linux' instead of 'Windows' though you are using Windows when you got the option to select Linux, Windows or Mac.
Since you are connecting to a server and not your own computer, the type of server you are connecting to is most likely Linux.

Connecting to a server and running a file with a GUI using bash on Windows and Xming

I'm running the Linux subsystem for Windows and Xming.
I am attempting to connect via ssh to a remote server and run a GUI program in Xming.
After initiating Xming, I run the following commands:
$ export DISPLAY=:0.0
$ ssh -X user#address
$ ./gui.sh
And I get the following error:
Unable to initialize GTK: could not open display
Exporting the display after I ssh returns the same error.
I have tried using ssh -Y as well.
Is this just a limitation of bash on Windows, or am I missing something?

ssh execute command remotely that not exist locally

Something like
ssh root#host "ls -l"
works fine
But when I'm trying
ssh root#host "showrgst"
I'm getting "command not found". And yes, I don't have showrgst command on the host I'm connected from.
How to solve this?
you need to install showrgst in the remote server and make sure the PATH env variable has the path to showrgst.
firstly, you can locate what executable is for this command
$ which showrgst
for example, it is executable script from $HOME/bin/showrgst.
So, you need to copy this file to server by means of scp -
$ scp ~/bin/showrgst youserver.com:/home/username/bin/
if this command is executable of some package existing in repositories linux disto, you can install this on your server

In command line, putty remote shell doesn't work, but in GUI, it does work

Using the GUI putty.exe, I can connect to my windows server and once it is connected, i can type any command like rename file or mkdir folder and they all work
However, using command line such as
putty -load test -m C:\users\test.txt
or using the GUI putty, but add 1 command to remote command in SSH under Connection, then the command doesn't get executed.
Can anyone explain to me why this is happening or how can i fix this? I am using FreeSSHd on windows 2008 server.
Not sure if this helps, but try adding the /bin/bash directly after your command in the text file. It will keep the window open and you can see what the output of the shell would be if you ran it from the gui.
; /bin/bash
For example if test.txt is running a script
bash myscript.sh
bash myscript.sh; /bin/bash
This is assuming bash.