博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
脚本练习
阅读量:3935 次
发布时间:2019-05-23

本文共 2100 字,大约阅读时间需要 7 分钟。

1.判断/tmp/run目录是否存在,如果不存在就建立,如果存在就删除目录里所有文件

在这里插入图片描述
在这里插入图片描述
2.输入一个路径,判断路径是否存在,而且输出是文件还是目录,如果是链接文件,还得输出是有效的连接还是无效的连接
在这里插入图片描述
在这里插入图片描述
3.交互模式要求输入一个ip,然后脚本判断这个IP对应的主机是否能ping通,输出结果类似于: Server 10.1.1.20 is Down! 最后要求把结果邮件到本地管理员root@localhost mail01@localhost
在这里插入图片描述
在这里插入图片描述
4.判断用户输入的字符串,如果是"hello",则显示"world";如果是"world", 则显示"hello"。
而脚本没有参数或者参数错误时,屏幕上输出 “usage:please input hello or world”
在这里插入图片描述
在这里插入图片描述
5.编辑一个脚本,实现自动搭建samba服务
#!/bin/bash
echo -e “\033[32m#######judge the network!!!\033[0m”
ping -c1 172.25.254.6 &>/dev/null
if [ $? -eq 0 ]
then
echo “the network is ok”
else
echo “Error:the network is not working”
exit 1
fi

echo -e "\033[32m######turnnig down the firewall and seliux!!!\033[0m "

setenforce 0 &>/dev/null
if [ $? -eq 0 ]
then
echo “selinux is disabled”
fi
systemctl stop firewalld &>/dev/null
if [ $? -eq 0 ]
then
echo “firewalld is stoped”
fi

echo -e " \033[32m#####judgeing wheather the sofeware install\033[0m"

rpm -q samba-common &>/dev/null
if [ $? -eq 0 ]
then
echo “samba-common is installed”
else
echo “samba-common is not installed”
dnf install samba-common -y
rpm -q samba-common &>/dev/null
if [ $? -eq 0 ]
then
echo “samba-common is now installed”
else
echo “samba-common installed failed”
exit 1
fi
fi

rpm -q samba &>/dev/null

if [ $? -eq 0 ]
then
echo “samba is installed”
else
echo “samba is not installed”
dnf install samba -y
rpm -q samba &>/dev/null
if [ $? -eq 0 ]
then
echo “samba is now installed”
else
echo “samba installed failed”
exit 1
fi
fi

rpm -q samba-client &>/dev/null

if [ $? -eq 0 ]
then
echo “samba-client is installed”
else
echo “samba-client is not installed”
dnf install samba-client -y
rpm -q samba-client &>/dev/null
if [ $? -eq 0 ]
then
echo “samba-client is now installed”
else
echo “samba-client installed failed”
exit
fi
fi

echo -e “\033[32m######startting the samba.service…\033[0m”

systemctl status smb.service | grep active &>/dev/null
if [ $? -eq 0 ]
then
systemctl restart smb
echo “smb.service restart success”
else
systemctl enable --now smb
fi

echo -e “\033[32m######add user and dir …!!!\033[0m”

read -p "please input a user: " user
read -p "please input a path: " path

useradd $user

mkdir -p $path

转载地址:http://xoegn.baihongyu.com/

你可能感兴趣的文章
create symbolic array
查看>>
TAUCS库的编译(vs2010)
查看>>
color vector using in plotting example points and lines between corresponding vertices
查看>>
mex 里面调用matlab函数
查看>>
matlab中cuda编程中分配grid和block dimension的时候的注意事项
查看>>
GPU CUDA and MEX Programming
查看>>
arrayfun用法
查看>>
矩阵积分
查看>>
optimization on macOS
查看>>
Template-Based 3D Model Fitting Using Dual-Domain Relaxation
查看>>
install libfreenect2 on ubuntu 16.04
查看>>
how to use automake to build files
查看>>
using matlab drawing line graph for latex
查看>>
How package finding works
查看>>
build opencv3.3.0 with VTK8.0, CUDA9.0 on ubuntu9.0
查看>>
how to compile kinfu_remake with cuda 9.0 opencv2.4.13.4
查看>>
qtcreator4.4.1中cmake 与cmake3.5.1本身generate出来的setting是有区别的解决方法
查看>>
CMake Useful Variables/Logging Useful Variables
查看>>
ubuntu下解决csdn网页打不开的问题
查看>>
MySQL server has gone away 问题的解决方法
查看>>