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