Write Linux scripts and linux scripts

Source: Internet
Author: User

Write Linux scripts and linux scripts

The following is a shell script for restarting a process in Linux. Take the tomcat process as an example:

#!/bin/shpid=`ps -ef|grep tomcat|grep -v grep|awk '{print $2}'`if [ "$pid" = "" ] ; then    echo "tomcat service does not start!"else    kill -9 $pid    pid1=`ps -ef|grep tomcat|grep -v grep|awk '{print $2}'`    if [ "$pid1" = "" ] ; then        echo "Successfully kill tomcat processes: " $pid    else        echo "tomcat kill process failed!"        exit 1    fifirm -rf /opt/tomcat/work/*./startup.shpid2=`ps -ef|grep tomcat|grep -v grep|awk '{print $2}'`if [ "$pid2" = "" ] ; then   echo "tomcat service failed to start!"else   echo "tomcat service starts successfully:" $pid2fi


In Linux, how do I write shell scripts?

Generally
#! /Bin/sh
(Not required, but must be a single line), specify the shell program to execute this script (you can also use #! /Bin/zsh or others), and then the heap command. Linux shell scripts support many functions. With highly modular Linux commands, you can use shell scripts to write complex programs.
The above is just a brief introduction to how to start writing shell scripts. if you want to write complex scripts, you also need to learn more about the relevant knowledge (such as if -- fi, case -- esac, and other structures ).
Of course, you also need to add executable permissions (chmod + x./file. sh) to the script. Otherwise, you can use
Sh./file. sh
Method to execute the script (here the sh is the shell required to execute the script, the command can also be zsh./file. sh or other ).

Linux script

I also came here, which means sed is used for processing.
Case Sensitive

1 #! /Bin/bash
2
3 [-z $1] & {echo "error"; exit 1 ;}
4
5 var = $1
6 grep "$1"/root/cmdline.txt | sed's/^. * = //'
7
8 exit 0

##############################
Supplement
To upstairs
Slightly optimize your Method
Inside = 'awk-F "=" '$1 ~ /INSIDE/{print $2} '</root/export line.txt'
Echo $ inside

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.