Nagios Tool, total running time for the tool - nagios

Is there any way to check for how long the NAGIOS TOOL runs? I mean when the tool started running and the time up till now.
Nagios is running in a remote machine, in which I have access (through ssh). I have both credentials for accessing the machine and credentials just to see the Stats from Nagios on this machine
I tried System->Process Info, but I do not have privileges to view such information.
Is there any other way, through terminal?

You can use nagiostats to check the uptime of a Nagios instance. See: https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/nagiostats.html
[nagios#lanman ~]# /usr/local/nagios/bin/nagiostats -c /usr/local/nagios/etc/nagios.cfg
Nagios Stats 3.0prealpha-05202006
Copyright (c) 2003-2007 Ethan Galstad (www.nagios.org)
Last Modified: 05-20-2006
License: GPL
CURRENT STATUS DATA
------------------------------------------------------
Status File: /usr/local/nagios/var/status.dat
Status File Age: 0d 0h 0m 9s
Status File Version: 3.0prealpha-05202006
Program Running Time: 0d 5h 20m 39s <------------
Nagios PID: 10119
Used/High/Total Command Buffers: 0 / 0 / 64
Used/High/Total Check Result Buffers: 0 / 7 / 512
...

Find the nagios.log file, it's likely in the var directory under the Nagios installation. Then..
grep "Nagios.*starting" nagios.log | tail -1
Grab the epoch time (first field), and convert it to local.
date -d #1580045430
Sun Jan 26 07:30:30 CST 2020
All in one, assuming the nagios.log is in the current directory.
date -d #$(grep "Nagios.*starting" nagios.log | tail -1 | awk '{print $1}' | sed 's/\[//;' | sed 's/\]//;')
Sun Jan 26 07:30:30 CST 2020

Related

linux azure web app not showing my reactjs app

I created a Reactjs web app using the npx create-react-app and created an azure ci/cd pipeline to push the build folder to my Linux web app instance.
i also specified startup command:
pm2 serve /home/site/wwwroot --no-daemon --spa
I verified that the build folder content is in the wwwroot folder but my Linux web app shows nothing.
my web app url: https://linux--dev.azurewebsites.net/
my web app content:
$ ls /home/site/wwwroot -al
total 37
drwxrwxrwx 2 nobody nogroup 4096 Mar 16 10:21 .
drwxrwxrwx 2 nobody nogroup 0 Mar 16 10:21 ..
-rwxrwxrwx 1 nobody nogroup 1092 Mar 16 10:21 asset-manifest.json
-rwxrwxrwx 1 nobody nogroup 3870 Mar 16 10:21 favicon.ico
-rwxrwxrwx 1 nobody nogroup 3010 Mar 16 10:21 index.html
-rwxrwxrwx 1 nobody nogroup 5347 Mar 16 10:21 logo192.png
-rwxrwxrwx 1 nobody nogroup 9664 Mar 16 10:21 logo512.png
-rwxrwxrwx 1 nobody nogroup 492 Mar 16 10:21 manifest.json
-rwxrwxrwx 1 nobody nogroup 67 Mar 16 10:21 robots.txt
drwxrwxrwx 2 nobody nogroup 0 Mar 16 10:21 static
2021-03-16T11:23:14.156072674Z _____
2021-03-16T11:23:14.156107475Z / _ \ __________ _________ ____
2021-03-16T11:23:14.156112975Z / /_\ \___ / | \_ __ \_/ __ \
2021-03-16T11:23:14.156116975Z / | \/ /| | /| | \/\ ___/
2021-03-16T11:23:14.156120475Z \____|__ /_____ \____/ |__| \___ >
2021-03-16T11:23:14.156124075Z \/ \/ \/
2021-03-16T11:23:14.156127375Z A P P S E R V I C E O N L I N U X
2021-03-16T11:23:14.156130575Z
2021-03-16T11:23:14.156133676Z Documentation: http://aka.ms/webapp-linux
2021-03-16T11:23:14.156136776Z NodeJS quickstart: https://aka.ms/node-qs
2021-03-16T11:23:14.156139976Z NodeJS Version : v14.15.1
2021-03-16T11:23:14.156143076Z Note: Any data outside '/home' is not persisted
2021-03-16T11:23:14.156146376Z
2021-03-16T11:23:14.318873080Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2021-03-16T11:23:14.318893181Z Could not find operation ID in manifest. Generating an operation id...
2021-03-16T11:23:14.318897181Z Build Operation ID: 9baf36d5-1dca-413f-929a-d66115f66772
2021-03-16T11:23:14.845130025Z Environment Variables for Application Insight's IPA Codeless Configuration exists..
2021-03-16T11:23:15.173100881Z Writing output script to '/opt/startup/startup.sh'
2021-03-16T11:23:15.352933180Z Running #!/bin/sh
2021-03-16T11:23:15.369142014Z
2021-03-16T11:23:15.369169414Z # Enter the source directory to make sure the script runs where the user expects
2021-03-16T11:23:15.369175515Z cd "/home/site/wwwroot"
2021-03-16T11:23:15.369179015Z
2021-03-16T11:23:15.369182315Z export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
2021-03-16T11:23:15.369185715Z if [ -z "$PORT" ]; then
2021-03-16T11:23:15.369189115Z export PORT=8080
2021-03-16T11:23:15.369192715Z fi
2021-03-16T11:23:15.369195915Z
2021-03-16T11:23:15.369200215Z PATH="$PATH:/home/site/wwwroot" pm2 serve /home/site/wwwroot --no-daemon --spa
2021-03-16T11:23:15.381752696Z /opt/startup/startup.sh: 11: /opt/startup/startup.sh: pm2: not found
did I miss something?
Try to use npx serve -s in your startup command.
It works for me.

i want to get the server name through Process from os level itself without connecting to DB

sybase 1215 30224 0 20:44 pts/3 00:00:00 grep dataserver
sybase 6138 6137 0 Feb04 ? 00:28:10 /u01/sybase/ASE15_0/ASE-15_0/bin/dataserver -d/u01/sybase/ASE15_0/data/aashish1_master.dat -e/u01/sybase/ASE15_0/ASE-15_0/install/aashish1.log -c/u01/sybase/ASE15_0/ASE-15_0/aashish1.cfg -M/u01/sybase/ASE15_0/ASE-15_0 -s**aashish1**
sybase 7671 1 0 Jan27 ? 00:55:50 /u01/sybase/ASE15_0/ASE-15_0/bin/dataserver -s**chaitu** -d/u01/sybase/ASE15_0/data/chaitu_master.dat -e/u01/sybase/ASE15_0/ASE-15_0/install/chaitu.log -c/u01/sybase/ASE15_0/ASE-15_0/chaitu.cfg -M/u01/sybase/ASE15_0/ASE-15_0
sybase 29479 29478 0 17:28 ? 00:00:33 /u01/sybase/ASE15_0/ASE-15_0/bin/dataserver -d/u01/sybase/ASE15_0/data/asdfg_master.dat -e/u01/sybase/ASE15_0/ASE-15_0/install/asdfg.log -c/u01/sybase/ASE15_0/ASE-15_0/asdfg.cfg -M/u01/sybase/ASE15_0/ASE-15_0 -s**asdfg** -psa
sybase 29617 29616 0 17:48 ? 00:00:33 /u01/sybase/ASE15_0/ASE-15_0/bin/dataserver -d/u01/sybase/ASE15_0/data/parbat.dat -e/u01/sybase/ASE15_0/ASE-15_0/install/parbat.log -c/u01/sybase/ASE15_0/ASE-15_0/parbat.cfg -M/u01/sybase/ASE15_0/ASE-15_0 -s**parbat**
sybase 29789 29788 0 17:57 ? 00:00:28 /u01/sybase/ASE15_0/ASE-15_0/bin/dataserver -d/u01/sybase/ASE15_0/data/ab123_master.dat -e/u01/sybase/ASE15_0/ASE-15_0/install/ab123.log -c/u01/sybase/ASE15_0/ASE-15_0/ab123.cfg -M/u01/sybase/ASE15_0/ASE-15_0 -s**ab123** -psa
[sybase#linuxerp scripts]$
I want to get the dataserver name from OS level itself without connecting to the Database.
ps -ef | grep dataserver
will get the server running or not
I tried to keep the output in a file and used grep -v on the file
Since the server name was not in exactly position, it is difficult to get the servername .
There are a couple of ways you can grab that information. One would be to pipe the grep output and use a regular expression:
ps -ef | grep dataserver | grep -oh '\-s[[:alnum:]]*' which should output something like this:
-saashish1
-schaitu
-sasdfg
-sparbat
-sab123
Another would be to use the showservers utility that comes installed with ASE, which outputs very similar to ps -ef but with CPU & Memory information as well as including other database servers such as the backup server, xp server, etc.
%> showserver
USER PID %CPU %MEM SZ RSS TT STAT START TIME COMMAND
user114276 0.0 1.7 712 1000 ? S Apr 5514:05 dataserver -d greensrv.dat -sgreensrv -einstall/greensrv+_errorlog
sybase 1071 0.0 1.4 408 820 ? S Mar 28895:38 /usr/local/sybase/bin/dataserver -d/dev/rsd1f -e/install/errorlog
user128493 0.0 0.0 3692 0 ? IW Apr 1 0:10 backupserver -SSYB_BACKUP -e/install/backup.log -Iinterfaces -Mbin/sybmultbuf -Lus_english -Jiso_1
And then pipe that into the same grep to get the information you are trying to find.
If you want to cut the -s off the front, to just get the servername itself, then you can pipe that into tr or cut.
Using tr you can tell it to delete -s from each line:
| tr -d '\-s'
Using cut you can tell it to print everything from the 3rd character to the end of the word:
| cut -c3-
Both of these will output your server names like this:
aashish1
chaitu
asdfg
parbat
ab123
Check this Question for information on using grep to grab single words.

copy db file with adb pull results in 'permission denied' error

I just rooted my Nexus 5 using this method: http://www.phonearena.com/news/How-to-root-Google-Nexus-5_id49014
I also enabled USB debugging in the developer options.
Then I tried to pull a database file from my device using this command:
adb pull /data/data/path.to.package/databases/data /sdcard/test
I get permission denied error.
I don't have the debugged flag set in that app I tried to access. Is that the reason I can't access that file? If yes, are there any workarounds to access an apps files?
You can use run-as shell command to access private application data.
If you only want to copy database you can use this snippet, provided in
https://stackoverflow.com/a/31504263/998157
adb -d shell "run-as com.example.test cat /data/data/com.example.test/databases/data.db" > data.db
I had the same problem. My work around is to use adb shell and su. Next, copy the file to /sdcard/Download
Then, I can use adb pull to get the file.
Did you try adb remount after giving adb root?
This generic solution should work on all rooted devices:
adb shell "su -c cat /data/data/com.android.providers.contacts/databases/contacts2.db" > contacts2.d
The command connects as shell, then executes cat as root and collects the output into a local file.
In opposite to #guest-418 s solution, one does not have to dig for the user in question.
Plus If you get greedy and want all the db's at once (eg. for backup)
for i in `adb shell "su -c find /data -name '*.db'"`; do
mkdir -p ".`dirname $i`"
adb shell "su -c cat $i" > ".$i"
done
This adds a mysteryous question mark to the end of the filename, but it is still readable.
If you get could not copy and permissions are right disable selinux.
Check if selinux is enabled.
$ adb shell
$su
# getenforce
Enforcing
Selinux is enabled and blocking/enforcing.
Disable selinux
# setenforce 0
do your stuff and set selinux to enforcing.
# setenforce 1
I had just the same problem, here's how to deal with it:
adb shell to the device
su
ls -l and check current access rights on the file you need. You'll need that later.
go to the file needed and: chmod 777 file.ext. Note: now you have a temporary security issue. You've just allowed all the rights to everyone! Consider adding just R for users.
open another console and: adb pull /path/to/file.ext c:\pc\path\to\file.exe
Important: after you're done, revert the access rights back to the previous value (point 3)
Someone mentioned something similar earlier.
Thanks for the comments below.
This answer ended up working for me: https://stackoverflow.com/a/15559278/53001
Backup to a file, pull the backup, and then convert it to a tarball and extract it.
adb backup -f myAndroidBackup.ab com.corp.appName
dd if=myAndroidBackup.ab bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xvf -
$ adb shell
$su
# getenforce
Enforcing
now try
adb shell
su
chmod 777 /path/to/yout_file
exit from shell
open new CMD and try adb pull /path/to/yout_file
It will work fine now.
you'll have security problems because of this any application will be able to access your database.
#guest-418 tips works well:
adb -d shell "run-as com.example.test cat /data/data/com.example.test/databases/data.db" > data.db
However, if you want to use a GUI, use Android Studio's Device File Explorer.
Launch Android Studio
Click on Device File Explorer at bottom right-side
Navigate to your app's file:
/data/data/path.to.package/databases/data
Right-mouse click select Save As and save to a local folder
I have been having Android Monitor hang on me lately on macOS. Device File Explorer works well for this purpose.
Create a folder in sdcard :
adb shell "su 0 mkdir /sdcard/com.test"
Move your files to the new folder :
adb shell "su 0 mv -F /data/data/com.test/files/ /sdcard/com.test/"
You can now use adb pull :
adb pull /sdcard/com.test
When executing adb commands, by default, a limited privileges user is used, the same kind of limited privilege user that is assigned to an app, and you have requested for all privelages to use all features of the device.
This kind of limited user helps protect your phone from malware, by restricting the access between apps, and the system. This is the reason you are unable to access app data and system data on an unrooted phone. The act of rooting means becoming user 0, the super user of the system, capable of any action, and is the highest privilege. Your apps however, are still secure in that they can not talk to eachother.
Now when accessing secure files, note that you do not want to change the permissions of the file when you access it, which may allow for vulnerabilities.
An option that you could use instead, is to make a copy of the file on the sdcard as root, modify that as a standard user, and then move it back into the filesystem as root, while preserving the file permissions of the original file.
Since I've updated to Android Oreo, I had to use this script to fix 'permission denied' issue.
This script on Mac OS X will copy your db file to Desktop. Just change it to match your ADB_PATH, DESTINATION_PATH and PACKAGE NAME.
#!/bin/sh
ADB_PATH="/Users/xyz/Library/Android/sdk/platform-tools"
PACKAGE_NAME="com.example.android"
DB_NAME="default.realm"
DESTINATION_PATH="/Users/xyz/Desktop/${DB_NAME}"
NOT_PRESENT="List of devices attached"
ADB_FOUND=`${ADB_PATH}/adb devices | tail -2 | head -1 | cut -f 1 | sed 's/ *$//g'`
if [[ ${ADB_FOUND} == ${NOT_PRESENT} ]]; then
echo "Make sure a device is connected"
else
${ADB_PATH}/adb exec-out run-as ${PACKAGE_NAME} cat files/${DB_NAME} > ${DESTINATION_PATH}
fi
This is a bit late, but installing adbd Insecure worked for me. It makes adb run in root mode on production ("secure") devices, which is what you likely have.
A paid version is also available on Google Play if you want to support the developer.
I had a similar problem to yours on windows as the following.
D:\ProgramFiles\Android> adb pull /data/local/tmp/com.packagename_dumped_1766.dex D:\ProgramFiles\Android\com.packagename_dumped_1766.dex
adb: error: failed to copy '/data/local/tmp/com.packagename_dumped_1766.dex' to 'D:\ProgramFiles\Android\com.packagename_dumped_1766.dex': remote Permission denied
My solution:
At first I also made an attempt to use cat as ansi_lumen answered, but I got into trouble about CR and LR (\r\n) characters.
And then I just had to change those file permisions by chmod and pulled again to this problem was solved without introducing other problems. After that, may
we need to restore their original permissions as Goran Devs answered.
So just pay a little attention.
TL;DR
My story:
Firstly, I used the cat to download all files from android to my windows,
#echo off
cd /d %~dp0
:: %~dp0 = D:\ProgramFiles\Android\
SET ThisBatDir=%~dp0
:: adb shell ls /data/local/tmp/com.packagename_dumped_* > %~dp0\dump_file_list.txt
FOR /f "delims=" %%a in ('adb shell ls /data/local/tmp/com.packagename_dumped_*') do call :processline %%a %%~nxa
goto :eof
:: https://stackoverflow.com/questions/232651/why-the-system-cannot-find-the-batch-label-specified-is-thrown-even-if-label-e
:processline
SET RemoteFullPath=%1
set FileName=%2
:: echo "%RemoteFullPath%|%ThisBatDir%|%FileName%"
call adb shell su -c cat %RemoteFullPath% > %ThisBatDir%%FileName%
goto :eof
:eof
However, those downloaded dex files were broken because of CR and LR (\r\n) characters on windows.
We can use hexdump to inspect its content in Hex+ASCII form (or Notepad++ with "View > Show Symbol > Show All Characters" checked). Note, the 5th and 6th byte (0d 0a)).
ssfang#MONITO ~
$ hexdump -C -n32 /cygdrive/d/ProgramFiles/Android/com.packagename_dumped_1448.dex # a bad dex
00000000 64 65 78 0d 0d 0a 30 33 35 00 f7 8e e4 b5 03 c6 |dex...035.......|
00000010 29 22 98 55 21 e9 70 49 fe c8 e4 cc fa 94 cd 63 |)".U!.pI.......c|
00000020
ssfang#MONITO ~
$ hexdump -C -n32 /cygdrive/d/ProgramFiles/Android/classes.dex # a normal dex
00000000 64 65 78 0a 30 33 35 00 b5 73 03 3a 0b 9d a2 47 |dex.035..s.:...G|
00000010 a8 78 a4 f0 bb e1 64 3f e5 b9 cb a0 bd 1b e2 71 |.x....d?.......q|
00000020
Versions
adb version // to check adb client version in your desktop
adb shell adbd --version // to check adbd's version in your Android. Please note that some users reported error with this if executed without root access.
D:\ProgramFiles\Android>adb version
Android Debug Bridge version 1.0.41
Version 29.0.6-6198805
Installed as D:\ProgramFiles\Android\Sdk\platform-tools\adb.exe
D:\ProgramFiles\Android>adb shell adb version
Android Debug Bridge version 1.0.32
Even if restarting adbd as root, it was still the shell user after .
D:\ProgramFiles\Android> adb root
restarting adbd as root
D:\ProgramFiles\Android> adb shell id
uid=2000(shell) gid=2000(shell) groups=1003(graphics),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:shell:s0
So I first viewed its file permision,
D:\ProgramFiles\Android> adb shell ls -l /data/local/tmp
-rwsr-sr-x shell shell 589588 2017-09-14 15:08 android_server
-rwsr-sr-x shell shell 1243456 2017-09-14 15:08 android_server64
-rw-rw-rw- shell shell 1536 2020-03-28 17:15 com.packagename.tar.gz
-rw-r----- root root 57344 2020-03-28 17:45 com.packagename_dumped_1766.dex
drwxrwxr-x shell shell 2018-08-12 09:48 device-explorer
-rwsrwsr-x shell shell 13592 2019-02-04 17:44 drizzleDumper
-rwxrwxrwx shell shell 5512504 2018-05-06 01:27 lldb-server
-rwxr-xr-x shell shell 12808 2020-03-26 22:16 mprop
then, changed its permision,
D:\ProgramFiles\Android> adb shell su -c chmod 777 /data/local/tmp/com.packagename_dumped_*
D:\ProgramFiles\Android> adb shell ls -l /data/local/tmp
-rwxrwxrwx root root 57344 2020-03-28 17:45 com.packagename_dumped_1766.dex
As a result, I made it.
D:\ProgramFiles\Android> adb pull /data/local/tmp/com.packagename_dumped_1766.dex D:\ProgramFiles\Android\com.packagename_dumped_1766.dex
/data/local/tmp/com.packagename_dumped_1766.de... 1 file pulled, 0 skipped. 3.6 MB/s (57344 bytes in 0.015s)
Now, jadx-gui-dev.exe or sh d2j-dex2jar.sh -f ~/path/to/apk_to_decompile.apk could properly enjoy them.
The pull command is:
adb pull source dest
When you write:
adb pull /data/data/path.to.package/databases/data /sdcard/test
It means that you'll pull from /data/data/path.to.package/databases/data and you'll copy it to /sdcard/test, but the destination MUST be a local directory. You may write C:\Users\YourName\temp instead.
For example:
adb pull /data/data/path.to.package/databases/data c:\Users\YourName\temp

/cygdrive/c and C:\ are different

I'm trying to run batch scripts via OpenSSH on Windows 8.1 but I'm getting this message:
bash: /cygdrive/c/Windows/System32/boot8.bat: No such file or directory
Somehow, the cygwin environment doesn't map C:\ to /cydrive/c correctly
Just to make sure, this is what mount says:
$ mount
C:/cygwin/bin on /usr/bin type ntfs (binary,auto)
C:/cygwin/lib on /usr/lib type ntfs (binary,auto)
C:/cygwin on / type ntfs (binary,auto)
C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
So, using cygwin shell I get this result:
$ ls -Al /cygdrive/c/Windows/System32 | grep boot
-rwxrwx---+ 2 TrustedInstaller TrustedInstaller 3072 Aug 22 06:14 api-ms-win-base-bootconfig-l1-1-0.dll
-rwxrwx---+ 2 TrustedInstaller TrustedInstaller 3170304 Jun 18 14:43 boot.sdi
-rwxrwx---+ 2 TrustedInstaller TrustedInstaller 79360 Aug 22 05:49 bootcfg.exe
If I however use the cmd window I can see the file:
C:\Windows\System32>dir | findstr boot
22/08/2013 12:21 165,376 bcdboot.exe
18/06/2013 16:08 3,170,304 boot.sdi
01/08/2013 15:24 290 boot7.bat
04/11/2013 16:00 298 boot8.bat
22/08/2013 12:15 87,040 bootcfg.exe
22/08/2013 10:17 13,312 bootim.exe
22/08/2013 13:45 109,408 bootsect.exe
22/08/2013 12:44 2,560 bootstr.dll
22/08/2013 10:07 3,311,616 bootux.dll
19/11/2013 16:42 307 bootxp.bat
Using the windows explorer, I can see the boot8.bat too.
It works under Windows XP and Windows 7. It doesn't matter whether or not you use capital letters for the Windows and system32 directory . I had this problem before, where I would edit files with notepad++ and when I later opened them with notepad they didn't change.
Any ideas?
try
ls -Al /cygdrive/c/Windows/sysnative | grep boot

Format file size in Unix in readable format

When I do ls -l I get
-rw-r--r-- 1 jboss admin **26644936** Sep 1 21:23 MyBig.war
How do I print it as below
-rw-r--r-- 1 jboss admin **26,644,936** Sep 1 21:23 MyBig.war
The proper way to format ls output is to specify BLOCK_SIZE.
Saying:
BLOCK_SIZE="'1" ls -l
would achieve your desired result.
Quoting from the above link:
Some GNU programs (at least df, du, and ls) display sizes in “blocks”.
You can adjust the block size and method of display to make sizes
easier to read.
A block size specification preceded by ‘'’ causes output sizes to be
displayed with thousands separators.
Using sed:
$ ls_output='-rw-r--r-- 1 jboss admin 26644936 Sep 1 21:23 MyBig.war'
$ echo $ls_output | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'
-rw-r--r-- 1 jboss admin 26,644,936 Sep 1 21:23 MyBig.war
Above sed command repeatedly replace the last 4 digits #### with #,###.
-e :a: Make a label named a for t command.
ta: Jump to a if substitution was successful.

Resources