运维Shell脚本小试牛刀(一)

运维Shell脚本小试牛刀(一)
运维Shell脚本小试牛刀(二)
一: Shell中循环剖析 for 循环.......
#!/bin/bash -
#==================================================================================================================
#
#
# FILE: countloop.sh
# USAGE: ./countloop.sh
# DESCRIPTION:
# OPTIONS: -------
# REQUIREMENTS: ---------
#
# BUGS: ------
# NOTES: --------
# AUTHOR: ---------YangGe (TOM) ,YangGe.freedom@icloud.com
# ORGANIZATION:
# CREATED: 2023-8-24 09:11:20
# REVISION: --------
#
#
#
#
#
#====================================================================================================================
for i in 1 2 3 4 5 6 #循环1~6
doecho "Thre for loop is run $i times."
done
echo "==============================================================================================================="for linux in Debian Redhat Suse Fedora Centos7 Ubunto
do
echo "current out system is ${linux}....."
done
echo "================================================================================================================"
#!/bin/bash -
#==================================================================================================================
#
#
# FILE: orcmdssub.sh
# USAGE: ./forcmdssub.sh
# DESCRIPTION:
# OPTIONS: -------
# REQUIREMENTS: ---------
#
# BUGS: ------
# NOTES: --------
# AUTHOR: ---------YangGe (TOM) ,YangGe.freedom@icloud.com
# ORGANIZATION:
# CREATED: 2023-8-24 09:11:20
# REVISION: --------
#
#
#
#
#
#====================================================================================================================
echo "Printing file list in /etc directory........"
for file in `ls /etc/*`
doecho "current print file is: $file"
done
#!/bin/bash -
#==================================================================================================================
#
#
# FILE: forcmdssub.sh
# USAGE: ./forcmdssub.sh
# DESCRIPTION:
# OPTIONS: -------
# REQUIREMENTS: ---------
#
# BUGS: ------
# NOTES: --------
# AUTHOR: ---------YangGe (TOM) ,YangGe.freedom@icloud.com
# ORGANIZATION:
# CREATED: 2023-8-24 09:11:20
# REVISION: --------
#
#
#
#
#
#====================================================================================================================
echo "Printing file list in /etc directory........"
for file in `ls /etc/*`
doecho "current print file is: $file"
done
[root@www shelldic]# cat forvarscoutents.sh
#!/bin/bash -
#==================================================================================================================
#
#
# FILE: forvarscoutents.sh
# USAGE: ./forvarscoutents.sh
# DESCRIPTION:
# OPTIONS: -------
# REQUIREMENTS: ---------
#
# BUGS: ------
# NOTES: --------
# AUTHOR: ---------YangGe (TOM) ,YangGe.freedom@icloud.com
# ORGANIZATION:
# CREATED: 2023-8-24 09:11:20
# REVISION: --------
#
#
#
#
#
#====================================================================================================================filenames="/etc/my.cnf /etc/vconsole.conf /etc/rsyncd.conf /etc/sestatus.conf /usr/local/rs.conf"
# 上面的文件名以空格分割for file in $filenames
do
[ -f $file ] && echo "The file $file was found.." || echo "***** ERROR: The file $file was missing.....*******"
# 如果是文件,则打印文件存在,如果不存在则打印丢失
done
#!/bin/bash -
#==================================================================================================================
#
#
# FILE: simplenestedfor.sh
# USAGE: ./simplenestedfor.sh
# DESCRIPTION:
# OPTIONS: -------
# REQUIREMENTS: ---------
#
# BUGS: ------
# NOTES: --------
# AUTHOR: ---------YangGe (TOM) ,YangGe.freedom@icloud.com
# ORGANIZATION:
# CREATED: 2023-8-24 09:11:20
# REVISION: --------
#
#
#
#
#
#====================================================================================================================
for (( i = 0; i < 30; i++ )) #外循环do
for (( j=0; j<160; j++ )) # 内循环
do
echo -n "* " #
doneecho "" #
done
二 : while循环
#!/bin/bash -
#==================================================================================================================
#
#
# FILE: whichreadfile.sh
# USAGE: ./whichreadfile.sh
# DESCRIPTION:
# OPTIONS: -------
# REQUIREMENTS: ---------
#
# BUGS: ------
# NOTES: --------
# AUTHOR: ---------YangGe (TOM) ,YangGe.freedom@icloud.com
# ORGANIZATION:
# CREATED: 2023-8-24 09:11:20
# REVISION: --------
#
#
#
#
#
#====================================================================================================================file=$1 # 将位置参数1的值赋值给变量file
if [ $# -lt 1 ];then # 如果脚本未指定参数,则打印使用方法并退出运行
echo "Usage: $0 FILEPATH"
exitfi
while read -r line # 使用read命令从标准输入读取文件的一行,并赋值给变量line
do
echo $line # 打印读取的行
done < "$file"
[root@www shelldic]# cat whilereadfile.sh
#!/bin/bash -
#==================================================================================================================
#
#
# FILE: whichreadfile.sh
# USAGE: ./whichreadfile.sh
# DESCRIPTION:
# OPTIONS: -------
# REQUIREMENTS: ---------
#
# BUGS: ------
# NOTES: --------
# AUTHOR: ---------YangGe (TOM) ,YangGe.freedom@icloud.com
# ORGANIZATION:
# CREATED: 2023-8-24 09:11:20
# REVISION: --------
#
#
#
#
#
#====================================================================================================================file=$1 # 将位置参数1的值赋值给变量file
if [ $# -lt 1 ];then # 如果脚本未指定参数,则打印使用方法并退出运行
echo "Usage: $0 FILEPATH"
exitfi
while read -r line # 使用read命令从标准输入读取文件的一行,并赋值给变量line
do
echo $line # 打印读取的行
done < "$file"
输出测试:
[root@www shelldic]# ./whilereadfile.sh /etc/sudo.conf
#
# Default /etc/sudo.conf file
#
# Format:
# Plugin plugin_name plugin_path plugin_options ...
# Path askpass /path/to/askpass
# Path noexec /path/to/sudo_noexec.so
# Debug sudo /var/log/sudo_debug all@warn
# Set disable_coredump true
#
# Sudo plugins:
#
# The plugin_path is relative to ${prefix}/libexec unless fully qualified.
# The plugin_name corresponds to a global symbol in the plugin
# that contains the plugin interface structure.
# The plugin_options are optional.
#
# The sudoers plugin is used by default if no Plugin lines are present.
Plugin sudoers_policy sudoers.so
Plugin sudoers_io sudoers.so#
# Sudo askpass:
#
# An askpass helper program may be specified to provide a graphical
# password prompt for "sudo -A" support. Sudo does not ship with its
# own passpass program but can use the OpenSSH askpass.
#
# Use the OpenSSH askpass
#Path askpass /usr/X11R6/bin/ssh-askpass
#
# Use the Gnome OpenSSH askpass
#Path askpass /usr/libexec/openssh/gnome-ssh-askpass#
# Sudo noexec:
#
# Path to a shared library containing dummy versions of the execv(),
# execve() and fexecve() library functions that just return an error.
# This is used to implement the "noexec" functionality on systems that
# support C<LD_PRELOAD> or its equivalent.
# The compiled-in value is usually sufficient and should only be changed
# if you rename or move the sudo_noexec.so file.
#
#Path noexec /usr/libexec/sudo_noexec.so#
# Core dumps:
#
# By default, sudo disables core dumps while it is executing (they
# are re-enabled for the command that is run).
# To aid in debugging sudo problems, you may wish to enable core
# dumps by setting "disable_coredump" to false.
#
# Set to false here so as not to interfere with /proc/sys/fs/suid_dumpable
#
Set disable_coredump false
相关文章:
运维Shell脚本小试牛刀(一)
运维Shell脚本小试牛刀(一) 运维Shell脚本小试牛刀(二) 一: Shell中循环剖析 for 循环....... #!/bin/bash - # # # # FILE: countloop.sh # USAGE: ./countloop.sh # DESCRIPTION: # OPTIONS: ------- # …...
screen命令,可以断开服务器连接,依旧能运行你的程序了
可以参考博客1:https://blog.csdn.net/nima_zhang_b/article/details/82797928 可以参考博客2:https://blog.csdn.net/herocheney/article/details/130984403 Linux中的screen是一个命令行工具,可以让用户在同一个终端会话中创建多个虚拟终端。它非常有…...
【ArcGIS Pro二次开发】(63):批量更改字段别名
在我工作中遇到的大多数图斑,字段名称一般是英文,字段别名是中文,使用起来是比较方便的。 但有时候也会遇到一些不一样的情况,不知是经过了怎样的处理,图斑的字段别名被修改成了和字段名称一样的英文,这样…...
redis全套参数配置及降级解决方案
文章目录 redis高可用核心参数配置1.Lettuce2.Jedis3.Redisson4.其他客户端 redis降级场景简介一、业务背景二、设计方案三、实现方案四、总结 redis高可用核心参数配置 1.Lettuce 提示:该客户端无主动探活机制,只能依赖于 OS KeepaAlive 机制…...
AMD即将上市大量中端显卡,为新显卡支付过高价格的日子可能结束
AMD在本周末(8月25日)的德国Gamescom活动中展示了两款新显卡和一些新的升级技术,这些新GPU的定价将与英伟达的GeForce RTX 4000卡竞争。 这是一件大事,因为新的Radeon RX 7700 XT和7800 XT卡占据了AMD Radeon RX 7000系列产品线…...
go学习一之go的初体验
go语言学习笔记 一、golang初体验: 1.简单体验案例: package main{ //把这个test.go归属到main import "fmt" //引入一个包 func main(){//输出hellofmt.Println("hello world")} }2.从案例学到的知识点: (1) go文件的后缀是.…...
智能制造产业链数字化转型、数字化互联工厂建设方案PPT
本资料来源公开网络,仅供个人学习,请勿商用,如有侵权请联系删除,更多浏览公众号:智慧方案文库 篇幅有限,无法完全展示,喜欢资料可转发评论,私信了解更多信息。...
【安卓】拿注册码的两种方式
【安卓】拿注册码的两种方式 文章仅用于学习交流,请勿利用文章中的技术对任何计算机系统进行入侵操作。利用此文所提供的信息而造成的直接或间接后果和损失,均由使用者本人负责。首发吾爱:https://www.52pojie.cn/thread-1826802-1-1.html言归…...
【C++】—— 异常处理
前言: 本期,我将给大家讲解的是有关 异常处理 的相关知识! 目录 (一)C语言传统的处理错误的方式 (二)C异常概念 (三)异常的使用 1、异常的抛出和捕获 1️⃣ 异常的…...
cookie和session是什么,区别是什么?
cookie HTTP 协议中的 Cookie 包括 Web Cookie 和浏览器 Cookie,它是服务器发送到 Web 浏览器的⼀ ⼩块数据。服务器发送到浏览器的 Cookie,浏览器会进⾏存储,并与下⼀个请求⼀起发送到服务器。通 常,它⽤于判断两个请求是否来⾃…...
linux的mmc子系统与块设备关联
1.前言 本文主要block组件的主要流程,在介绍的过程中,将详细说明和block相关的流程,涉及到其它组件的详细流程再在相关文章中说明。 2.主要数据结构和API 2.1 struct mmc_card Elemete Namestruct mmc_cardPathinclude/linux/mmc/card.hRe…...
【Spring MVC】
目录 🍮1 什么是 MVC ? 🎁2 Spring MVC 的连接 🍘2.1 RequestMapping 实现 POST 和 GET 请求 🥣2.2 GetMapping 只支持 GET 请求 🫖2.3 PostMapping 只支持 POST 请求 🍬3 Spring MVC 获取参数的…...
【ES】笔记-生成器函数与调用
function* function* 这种声明方式 (function关键字后跟一个星号)会定义一个生成器函数 (generator function),它返回一个 Generator 对象。 function * gen(){console.log("heloo generator")}如何调用呢?先看下里面的内容 返回…...
将Spring Boot与Redis集成
一、引言 1、SpringBoot: Spring Boot是一个用于创建独立且可执行的Spring应用程序的框架。它简化了基于Spring框架的应用程序的开发过程,并提供了一种快速和简便的方式来构建Java应用程序。 Spring Boot提供了自动配置机制,通过引入适当的…...
vue echarts
安装 npm i -D echarts使用 <script setup lang"ts"> import * as echarts from echarts import { onMounted } from vueonMounted(() > {interface DataItem {value: [string, number]}let myChart echarts.init(document.getElementById(main))let dat…...
idea上利用JDBC连接MySQL数据库(8.1.0版)
1.了解jdbc概念 JDBC(Java DataBase Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种 关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成。JDBC提供了一种基准,据此可以构建 更高级的工具和接口&#…...
【100天精通python】Day47:python网络编程_Web编程基础
目录 1 网络编程与web编程 1.1 网络编程 1.2 web编程 2 Web开发概述 3 Web开发基础 3.1 HTTP协议 3.2 Web服务器 3.3 前端基础 3.4 静态服务器 3.5 前后端交互的基本原理 4 WSGI接口 4.1 CGI 简介 4.2 WSGI 简介 4.3 定义 WSGI 接口 4.4 运行 WSGI 服务 4.5…...
DockerCompose介绍与使用
DockerCompose介绍与使用 1、DockerCompose介绍 DockerCompose用于定义和运行多容器 Docker 应用程序的工具。 通过 Compose可以使用 YAML 文件来配置应用程序需要的所有服务。一个使用Docker容器的应用,通常由多个容器组成,使用Docker Compose不再需要…...
Windows Qt 5.12.10下载与安装
Qt 入门实战教程(目录) C自学精简实践教程 目录(必读) 1 Qt5.12.10下载 qt-opensource-windows-x86-5.12.10.exe 官方离线安装包 Download Source Package Offline Installers | Qt 下载巨慢(也可能很快) 只能下载到最新的&…...
RustDesk最新版本编译与打包
本文环境 主要参考: https://www.yuque.com/shikangsi/efy0cp/wei3g1?https://blog.csdn.net/hualuohuakai2014/article/details/121605631 问题 flutter 生成 bridge 文件。 先安装工具,再生成ffi文件。 PS C:\Users\Administrator> cargo ins…...
网络编程(Modbus进阶)
思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…...
高频面试之3Zookeeper
高频面试之3Zookeeper 文章目录 高频面试之3Zookeeper3.1 常用命令3.2 选举机制3.3 Zookeeper符合法则中哪两个?3.4 Zookeeper脑裂3.5 Zookeeper用来干嘛了 3.1 常用命令 ls、get、create、delete、deleteall3.2 选举机制 半数机制(过半机制࿰…...
CocosCreator 之 JavaScript/TypeScript和Java的相互交互
引擎版本: 3.8.1 语言: JavaScript/TypeScript、C、Java 环境:Window 参考:Java原生反射机制 您好,我是鹤九日! 回顾 在上篇文章中:CocosCreator Android项目接入UnityAds 广告SDK。 我们简单讲…...
【RockeMQ】第2节|RocketMQ快速实战以及核⼼概念详解(二)
升级Dledger高可用集群 一、主从架构的不足与Dledger的定位 主从架构缺陷 数据备份依赖Slave节点,但无自动故障转移能力,Master宕机后需人工切换,期间消息可能无法读取。Slave仅存储数据,无法主动升级为Master响应请求ÿ…...
什么?连接服务器也能可视化显示界面?:基于X11 Forwarding + CentOS + MobaXterm实战指南
文章目录 什么是X11?环境准备实战步骤1️⃣ 服务器端配置(CentOS)2️⃣ 客户端配置(MobaXterm)3️⃣ 验证X11 Forwarding4️⃣ 运行自定义GUI程序(Python示例)5️⃣ 成功效果 img 属性介绍: img 属性指定分区存放的 image 名称,指定的 image 名称必须是当前工程生成的 binary 。 如果 binary 有多个文件,则以 proj_name:binary_name 格式指定文件名, proj_name 为工程 名&…...
基于TurtleBot3在Gazebo地图实现机器人远程控制
1. TurtleBot3环境配置 # 下载TurtleBot3核心包 mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src git clone -b noetic-devel https://github.com/ROBOTIS-GIT/turtlebot3.git git clone -b noetic https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git git clone -b noetic-dev…...
推荐 github 项目:GeminiImageApp(图片生成方向,可以做一定的素材)
推荐 github 项目:GeminiImageApp(图片生成方向,可以做一定的素材) 这个项目能干嘛? 使用 gemini 2.0 的 api 和 google 其他的 api 来做衍生处理 简化和优化了文生图和图生图的行为(我的最主要) 并且有一些目标检测和切割(我用不到) 视频和 imagefx 因为没 a…...
免费数学几何作图web平台
光锐软件免费数学工具,maths,数学制图,数学作图,几何作图,几何,AR开发,AR教育,增强现实,软件公司,XR,MR,VR,虚拟仿真,虚拟现实,混合现实,教育科技产品,职业模拟培训,高保真VR场景,结构互动课件,元宇宙http://xaglare.c…...
Chromium 136 编译指南 Windows篇:depot_tools 配置与源码获取(二)
引言 工欲善其事,必先利其器。在完成了 Visual Studio 2022 和 Windows SDK 的安装后,我们即将接触到 Chromium 开发生态中最核心的工具——depot_tools。这个由 Google 精心打造的工具集,就像是连接开发者与 Chromium 庞大代码库的智能桥梁…...
