Two simple shell scripts (about startup and service)

Source: Internet
Author: User

Experimental requirements:

1. Write a login welcome script for root user, report the number of processes in the current host, the number of logged in users, and the disk usage of the root file system.

2, write three scripts: Start,stop and status, used to start, stop various system services


Experimental steps:

[Email protected] ~]# VI welcome.sh


#!/bin/bash

# This is test.by Shengjie


p= ' ps aux | Wc-l '//Set Variable P

echo "Running Processes: $p"

U= ' who | Wc-l '//Set Variable U

echo "Login Users: $u"

D= ' Df-ht | grep "/$" | awk ' {print $6} '//Set Variable D

echo "Usage Of/filesystem: $d"

: Wq Save Exit


[Email protected] ~]# Vi. bash_profile

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/53/D2/wKiom1RxbvCxK1RzAAEdmZKD-Vo521.jpg "title=" Shell.jpg "alt=" Wkiom1rxbvcxk1rzaaedmzkd-vo521.jpg "/>


Restart the system, you can see the following information

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/53/D0/wKioL1Rxb6-jnrUCAAEGd5R-nUU616.jpg "title=" Shell2.jpg "alt=" Wkiol1rxb6-jnrucaaegd5r-nuu616.jpg "/>


[Email protected] ~]# echo $PATH

/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[Email protected] ~]# Cd/bin

[Email protected] bin]# VI start.sh


#!/bin/bash

# This is test


Service start//$1 is the position variable, call the content after start, if start Crond, then service Crond start

: Wq


[[email protected] bin]# alias start= ' start.sh '


Take Crond as an example, run start Crond (if prompted without permission, you need to switch to the bin directory to add execution permissions to start.sh: chmod +x/bin/start.sh)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/53/D2/wKiom1RxcdiAm6r8AABJEe_Czok191.jpg "title=" Shell3.jpg "alt=" Wkiom1rxcdiam6r8aabjee_czok191.jpg "/>

Stop and status with start, modify the shell script.



This article is from the "Network growth path of the female kicked" blog, please make sure to keep this source http://shengjie.blog.51cto.com/8734352/1581638

Two simple shell scripts (about startup and service)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.