Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Help to prepare script for monitor services Post 303045419 by yash_message on Friday 20th of March 2020 08:47:10 AM
Old 03-20-2020
Help to prepare script for monitor services

I need to monitor services in rhel 8
below are the service......
crond
chronyd
rsyslogd
sshd
sssd
firewalld

Scripts..........
Code:
#!/bin/bash
for i in "${SERVICES[@]}"
do
###CHECK SERVICE####
`pgrep $i `
STATS=(echo $?)

if [  $STATS == 0  ]
then
echo   "$i is running"
else
echo   "$i is not running"
fi
done

but after run script, output does not come. please help, where is the problem in scripts.

--- Post updated at 07:17 PM ---

I prepared another script. but getting error.

Code:
#!/bin/bash
for i in `cat SERVICES`
do
###CHECK SERVICE####
status=systemctl | grep running |grep $i |awk '{print $4}'
if [ $status -eq running ]
then
     echo "$i is running"
else
     echo "$i is not running"
fi
done

Output-

[root@localhost ~]# sh service1.sh
service1.sh: line 6: [: -eq: unary operator expected
crond is not running
service1.sh: line 6: [: -eq: unary operator expected
chronyd is not running
service1.sh: line 6: [: -eq: unary operator expected
rsyslogd is not running
service1.sh: line 6: [: -eq: unary operator expected
sshd is not running
service1.sh: line 6: [: -eq: unary operator expected
sssd is not running
service1.sh: line 6: [: -eq: unary operator expected
firewalld is not running


Why it is coming error.
 

10 More Discussions You Might Find Interesting

1. SuSE

Script to disable services

Hi All, I want to disable bunch of unused services on SLES and RHEL to improve the performance. Since we have more than 100 servers to disable services, I want to do with some script. Any one can give me an idea how to write a script to disable services. Thanks (1 Reply)
Discussion started by: s_linux
1 Replies

2. AIX

Startup script and services

Guy's What the exact steps to mention for example this script /usr/start/start.sh to be as start up script , I want it to be automatically started when I reboot the server . (8 Replies)
Discussion started by: ITHelper
8 Replies

3. AIX

How to monitor websphere services down?

if websphere services is down, any unix command or scripts can send alert? (1 Reply)
Discussion started by: rainbow_bean
1 Replies

4. Shell Programming and Scripting

Need script to restart the services

Hi Guys, I need bash script to restart the service. 1. Disable the service called SASM svcadm disable sasm 2. if service went to maintenance mode then it shuld clear it with below command svcadm clear sasm 3.or else it should restart the mysql service /etc/init.d/mysql stop... (1 Reply)
Discussion started by: bapu1981
1 Replies

5. Red Hat

Restart of services if port no is changed in /etc/services in RHEL

I had a doubt if any services need to be restarted if port no in /etc/services in an RHEL setup is changed. For eg, the port no of 443 for SSL may need to be changed. I hope my query is clear whether any services need to be restarted if port no in /etc/services is changed. Please revert with... (10 Replies)
Discussion started by: RHCE
10 Replies

6. Shell Programming and Scripting

Script to Start services based on dependent services on other AIX machine

Hi, I just started working on a script. After my research, i found a command which can help me: AIM: To build a script which starts the services (Services 1) on server 1 automatically whenever its down. And it has a dependency on other service (Service 2) on Server 2. So my script has to... (4 Replies)
Discussion started by: draghun9
4 Replies

7. Shell Programming and Scripting

Monitor the services by script

I developed for monitoring the network connections among the branch servers as I given below as script.But I don't know how to monitor the services through network script whether the services is running or not. eg : I want to check the postgres service for all the branch servers through network... (0 Replies)
Discussion started by: kannansoft1985
0 Replies

8. Shell Programming and Scripting

Monitor some of network services

Hi I want to write a script for netflow service because my service doesnt send any packet to netflow walker (server). Although the service is started but it does not send any packet to server until i restart the service I want to write a script in order to restart the service... (7 Replies)
Discussion started by: mohsen1366
7 Replies

9. Infrastructure Monitoring

Searching for Saas Monitor service which monitor my servers which are sitting in different providers

Sorry if this is the wrong forum Searching for Saas Monitor service which monitor my servers which are sitting in different providers . This monitor tool will take as less CPU as possible , and will send info about the server to main Dashboard. The info I need is CPU / RAM / my servers status (... (1 Reply)
Discussion started by: umen
1 Replies

10. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies
svcs(1) 																   svcs(1)

NAME
svcs - report service status SYNOPSIS
svcs [-aHpv?] [-o col[,col]...] [-R instance_FMRI]... [-sS col]... [FMRI | pattern] ... svcs {-d | -D} [-Hpv?] [-o col[,col]...] [-sS col]... [FMRI | pattern] ... svcs -l [FMRI | pattern] ... svcs -x [-v] [FMRI]... The svcs command displays information about service instances as recorded in the service configuration repository. The first form prints one-line status listings for service instances specified by the arguments. Each instance is listed only once. With no arguments, all enabled service instances, even if temporarily disabled, are listed with the columns indicated below. The second form prints one-line sta- tus listings for the dependencies or dependents of the service instances specified by the arguments. The third form prints detailed infor- mation about specific services and instances. The fourth form explains the states of service instances. For each argument, a block of human-readable text is displayed which explains what state the service is in, and why it is in that state. With no arguments, problematic services are described. Error messages are printed to the standard error stream. The following options are supported: -? Displays an extended usage message, including column specifiers. -a Show all services, even disabled ones. This option has no effect if services are selected. -d Lists the services or service instances upon which the given service instances depend. -D Lists the service instances that depend on the given services or service instances. -H Omits the column headers. -l (The letter ell.) Displays all available information about the selected services and service instances, with one service attribute displayed for each line. Information for different instances are separated by blank lines. The following specific attributes require further explanation: dependency Information about a dependency. The grouping and restart_on properties are displayed first and are separated by a/. Next, each entity and its state is listed. See smf(5) for information about states. In addition to the standard states, each service dependency can have the following state descriptions: absent No such service is defined on the system. invalid The FMRI is invalid. multiple The entity is a service with multiple instances. File dependencies can only have one of the following state descriptions: absent No such file on the system. online The file exists. If the file did not exist the last time that svc.startd evaluated the service's dependencies, it can con- sider the dependency to be unsatisfied. svcadm refresh forces dependency re-evaluation. unknown stat(2) failed for a reason other than ENOENT. See smf(5) for additional details about dependencies, grouping, and restart_on values. enabled Whether the service is enabled or not, and whether it is enabled or disabled temporarily (until the next system reboot). The former is specified as either true or false, and the latter is designated by the presence of (tem- porary). A service might be temporarily disabled because an administrator has run svcadm disable -t, used "svcadm mile- stone, or booted the system to a specific milestone. See svcadm(1M) for details. -o col[,col]... Prints the specified columns. Each col should be a column name. See COLUMNS below for available columns. -p Lists processes associated with each service instance. A service instance can have no associated processes. The process ID, start time, and command name (PID, STIME, and CMD fields from ps(1)) are displayed for each process. -R instance_FMRI Selects service instances that have the given service instance as their restarter. -s col Sorts output by column. col should be a column name. See COLUMNS below for available columns. Multiple -s options behave additively. -S col Sorts by col in the opposite order as option -s. -v Without -x, displays verbose columns: STATE, NSTATE, STIME, CTID, and FMRI. With -x, displays extra information for each explanation. -x Displays explanations for service states. Without arguments, the -x option explains the states of services which: o are enabled, but are not running. o are preventing another enabled service from running. The following operands are supported: instance_FMRI An FMRI that specifes an instance. FMRI An FMRI that specifes one or more instances. FMRIs can be abbreviated by specifying the instance name, or the trailing por- tion of the service name. For example, given the FMRI: svc:/network/smtp:sendmail The following are valid abbreviations: sendmail :sendmail smtp smtp:sendmail network/smtp The following are invalid abbreviations: mail network network/smt If the FMRI specifies a service, then the command applies to all instances of that service, except when used with the -D option. Abbreviated forms of FMRIs are unstable, and should not be used in scripts or other permanent tools. pattern A pattern that is matched against the FMRIs of service instances according to the "globbing" rules described by fnmatch(5). If the pattern does not begin with svc:, then svc:/ is prepended. COLUMNS
Column names are case insensitive. The default output format is equivalent to "-o state,stime,fmri". The default sorting columns are STATE, STIME, FMRI. CTID The primary contract ID for the service instance. Not all instances have valid primary contract IDs. DESC A brief description of the service, from its template element. A service might not have a description available, in which case a hyphen (-) is used to denote an empty value. FMRI The FMRI of the service instance. INST The instance name of the service instance. NSTA The abbreviated next state of the service instance, as given in the STA column description. A hyphen denotes that the instance is not transitioning. Same as STA otherwise. NSTATE The next state of the service. A hyphen is used to denote that the instance is not transitioning. Same as STATE otherwise. SCOPE The scope name of the service instance. SVC The service name of the service instance. STA The abbreviated state of the service instance: DGD degraded DIS disabled LRC legacy rc*.d script-initiated instance MNT maintenance OFF offline ON online UN uninitialized Absent or unrecognized states are denoted by a question mark (?) character. An asterisk (*) is appended for instances in transition, unless the NSTA or NSTATE column is also being displayed. See smf(5) for an explanation of service states. STATE The state of the service instance. An asterisk is appended for instances in transition, unless the NSTA or NSTATE column is also being displayed. See smf(5) for an explanation of service states. STIME If the service instance entered the current state within the last 24 hours, this column indicates the time that it did so. Otherwise, this column indicates the date on which it did so, printed with underscores (_) in place of blanks. Example 1: Displaying the Default Output This example displays default output: example% svcs STATE STIME FMRI ... legacy_run 13:25:04 lrc:/etc/rc3_d/S42myscript ... online 13:21:50 svc:/system/svc/restarter:default ... online 13:25:03 svc:/milestone/multi-user:default ... online 13:25:07 svc:/milestone/multi-user-server:default ... Example 2: Listing All Local Instances This example lists all local instances of the service1 service. example% svcs -o state,nstate,fmri service1 STATE NSTATE FMRI online - svc:/service1:instance1 disabled - svc:/service1:instance2 Example 3: Listing Verbose Information This example lists verbose information. example% svcs -v smtp STATE NSTATE STIME CTID FMRI online - 13:25:13 141 svc:/network/smtp:sendmail Example 4: Listing Detailed Information This example lists detailed information about all instances of system/service3. Additional fields can be displayed, as appropriate to the managing restarter. example% svcs -l system/service3 fmri svc:/system/service3:default description Example service 3 enabled true state online next_state none restarter svc:/system/svc/restarter:default dependency require_all/refresh svc:/system/service2:default (online) dependency require_all/none svc:/system/service1:default (online) fmri svc:/system/service3:backup description Example service 3 enabled false state disabled next_state none restarter svc:/system/svc/restarter:default dependency require_all svc:/system/service2:backup (absent) Example 5: Listing Processes example% svcs -p sendmail STATE STIME FMRI online 13:25:13 svc:/network/smtp:sendmail 13:25:15 100939 sendmail 13:25:15 100940 sendmail The following exit values are returned: 0 Successful command invocation. 1 Fatal error. 2 Invalid command line options were specified. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Interface Stability |See below. | +-----------------------------+-----------------------------+ The human readable output is Unstable. The invocation is Evolving. ps(1), svcprop(1), svcadm(1M), svccfg(1M), svc.startd(1M), stat(2), libscf(3LIB), attributes(5), fnmatch(5), smf(5) 18 Mar 2005 svcs(1)
All times are GMT -4. The time now is 09:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy