• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >linux shell > 自己常用的一些shell脚本分享

自己常用的一些shell脚本分享

作者:junjie 字体:[增加 减小] 来源:互联网

junjie 通过本文主要向大家介绍了linux常用shell脚本,常用shell脚本,shell脚本常用命令,运维常用shell脚本,shell脚本编程大全等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

自己写了一下小的shell实例,虽然很小,但所有的大的程序都是由小的模块堆积起来的,程序员一定要懂得一种脚本的书写,而我,只会在linux下工作,所以就只能写linux的shell脚本了,呵呵,本文会陆续更新,给自己加油!

1.模拟linnux登录shell
#/bin/bash
echo -n "login:"
read name
echo -n "password:"
read passwd
if [ $name = "cht" -a $passwd = "abc" ];then
echo "the host and password is right!"
else echo "input is error!"
fi
</div>
2.比较两个数大小
#/bin/bash
echo "please enter two number"
read a
read b
if test $a -eq $b
then echo "NO.1 = NO.2"
elif test $a -gt $b
then echo "NO.1 > NO.2"
else echo "NO.1 < NO.2"
fi
</div>
3.查找/root/目录下是否存在该文件
#/bin/bash
echo "enter a file name:"
read a
if test  -e /root/$a
then echo "the file is exist!"
else echo "the file is not exist!"
fi
</div>
4.for循环的使用
#/bin/bash
clear
for num in 1 2 3 4 5 6 7 8 9 10
do
    echo "$num"
done
</div>
5.
#/bin/bash
echo "Please enter a user:"
read a
b=$(whoami)
if test $a = $b
then echo "the user is running."
else echo "the user is not running."
fi
</div>
6.删除当前目录下大小为0的文件
#/bin/bash
for filename in `ls`
do
    if test -d $filename
    then b=0
    else   
       a=$(ls -l $filename | awk '{ print $5 }')
            if test $a -eq 0
             then rm $filename
             fi
        fi     
done
</div>
7.如果/export/um_lpp_source下有文件,那么将其文件系统大小改为3G
#/bin/bash
while line=`ls /export/um_lpp_source`
do
        if test $line=""
        then  echo "NULL"
             sleep 1
    else echo $line
                chfs -a size=3G /export/um_lpp_source
                 exit 0
        fi
done
</div>
 
8.测试IP地址
#/bin/bash
for i in  1 2 3 4 5 6 7 8 9
do
    echo "the number of $i computer is "
    ping -c 1 192.168.0.$i
done
</div>
9.如果test.log的大小大于0,那么将/opt目录下的*.tar.gz文件
#/bin/sh
a=2
while name="test.log"
do
        sleep 1
        b=$(ls -l $name | awk '{print $5}')
        if test $b -ge $a
        #then echo "OK"
    then `cp /opt/*.tar.gz .`
        exit 0
        fi
done
</div>
10.打印读取的内容,为下面的例子做准备
#/bin/bash
while read name
do
echo $name
done
</div>
11.从0.sh中读取内容并打印
#/bin/bash
while read line
do
    echo $line
done < 0.sh
</div>
12.读取a.c中的内容并做加1运算
#/bin/bash
test -e a.c
while read line
do
    a=$(($line+1))
done < a.c
echo $a
</div>
13.普通无参数函数
#/bin/bash
p ()
{
    echo "hello"
}
p
</div>
14.给函数传递参数
#/bin/bash
p_num ()
{
    num=$1
    echo $num
}
for n in $@
do
    p_num $n
don

您可能想查找下面的文章:

  • 使用Linux shell脚本实现FTP定时执行批量下载指定文件
  • Linux shell脚本输出日志笔记整理(必看篇)
  • Linux下使用shell脚本自动执行脚本文件
  • Linux Shell脚本的编程之正则表达式
  • Linux下Shell脚本中几种基本命令的替换区别
  • Linux Shell脚本面试25问集合
  • Linux下一些常用的Shell脚本整理
  • Linux Shell脚本系列教程(七):脚本调试
  • Linux Shell脚本系列教程(六):数组和关联数组
  • Linux Shell脚本系列教程(五):数学运算

相关文章

  • Linux之split命令详解
  • rsync结合find技巧分享
  • shell脚本实现批量采集爱站关键词库
  • shift妙用之解决shell编程中的入参问题
  • Shell脚本读取标准ini配置文件Demo
  • 一键配置CentOS iptables防火墙的Shell脚本分享
  • shell脚本监控linux系统内存使用情况的方法(不使用nagios监控linux)
  • 一天一个shell命令 linux文本内容操作系列-cut命令详解
  • Shell中的循环语句for、while、until实例讲解
  • shell脚本操作oracle删除表空间、创建表空间、删除用户

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • linux shell 路径截取正则表达式
    • Linux中多命令执行';'和'&&'的区别解释
    • 程序中获取linux系统启动时间方法
    • Linux Shell脚本系列教程(六):数组和关联数组
    • shell去掉文件中空行(空白行)的方法详解
    • Bash中数组的操作教程
    • php编译安装常见错误大全和解决方法
    • 关于vi和vim的区别及命令详解
    • shell两个文件去重的多种姿势
    • linux shell数据重定向(输入重定向与输出重定向)详细分析

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有