#!/bin/bash
service=service_name
email=user@domain.com
host=`hostname -f`
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running"
else
/etc/init.d/$service start
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
subject="$service at $host has been started"
echo "$service at $host wasn't running and has been started" | mail -s "$subject" $email
else
subject="$service at $host is not running"
echo "$service at $host is stopped and cannot be started!!!" | mail -s "$subject" $email
fi
fi
如何让这个脚本在后台运行,以便它继续检查httpd服务是打开还是关闭,并在消息发出时通过电子邮件发送消息!! (PS-:我不想把这个脚本作为一个CRONJOB)就像一个在后台运行的守护进程! 请帮忙
答案 0 :(得分:3)
如果使用nohup启动脚本,它将作为守护程序运行。
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:padding="0dp"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_brand"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/NoActionBarTheme">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearPesanan"
android:background="@drawable/hover_selector40ffffff"
android:paddingLeft="-15dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.90"
android:scaleY="0.90"
android:src="@drawable/assets_left_arrow_white"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Pesanan"
android:textColor="@android:color/white"
android:textStyle="bold"
android:textSize="16sp"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_brand"
app:tabMode="scrollable"
app:tabGravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#cccccc"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="0.30"
android:paddingLeft="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Semua pesanan"
android:layout_gravity="center_vertical"
android:fontFamily="sans-serif-light"
android:id="@+id/semuaPesanan"
android:textSize="14sp"
android:textColor="#333333"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="0.70"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Filter"
android:fontFamily="sans-serif-light"
android:id="@+id/pesananFilter"
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material"
android:layout_gravity="center_horizontal"
android:textSize="14sp"
android:textColor="#333333"/>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_gravity="fill_vertical"
android:layout_height="fill_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>