标签:let ali The dom copyright bashrc img user 自动
1、创建用户脚本
#!/bin/bash
#
#********************************************************************
#Author: 小汤圆
#:
#Date: 2019-12-04
#FileName: CreateUser.sh
#URL: 暂无
#Description: The test script
#Copyright (C): 2019 All rights reserved
#QQ Address 2382990774
#**************************************************************
COLOR=‘\033[1;31m‘
COLOREND=‘\033[0m‘
useradd $*
echo -e "$COLOR User $* is ‘created‘ $COLOREND"
注释:$*为系统自带变量,$COLOR和$COLOREND为自定义的变量,想修改显示的颜色可以很方便的修改。
2、复制文件到其他机器
#!/bin/bash
#**************************************************************
COLOR=‘\033[1;32m‘
COLOREND=‘\033[0m‘
echo -e "$COLOR ‘start‘$COLOREND"
scp -r $* root@192.168.27.102:/data/
echo -e "$COLOR ‘over‘$CLOOREND"
注释:user.sh 为文件名,加-r可以传文件也可以传文件夹
3、删除改为移到到某个文件夹
#!/bin/bash
#**************************************************************
CurrentTime=`date ‘+%F_%s‘`
DestinationDir=‘/tmp‘
Color=‘\033[1;33m‘
ColorEnd=‘\033[0m‘
mkdir -p $DestinationDir/$CurrentTime
mv $* $DestinationDir/$CurrentTime/
echo -e "$Color move complete. you will find the files that is deleted in $DestinationDir/$CurrentTime $ColorEnd"
注释:alias rm=‘/data/scripts37/rm.sh‘ 定义别名rm等于刚刚创建的脚本,执行rm就自动执行脚本
定义别名的地方 直接在根目录下输入vim .bashrc,或者在随便什么目录下输入vim ~/.bashrc
$[RANDOM%7+31 颜色随机
4、编写计算鸡兔同笼
#!/bin/bash
#********************************************************************
Color="\033[$[RANDOM%7+31]m"
ColorEnd="\033[0m"
read -p "Input head number: " head
read -p "Input foot number: " foot
rabbit=$[foot/2-head]
chook=$[head-rabbit]
echo -e $Color"rabbit:$rabbit chook:$chook"$ColorEnd
注释:$[RANDOM%7+31 颜色随机
5、编写ping脚本
#!/bin/bash
#********************************************************************
ping -c1 -W2 $* > /dev/null && echo "$* is up" || echo "$* is unreachable"
-----------
#!/bin/bash
#
#********************************************************************
Color="\033[$[RANDOM%7+31]m"
ColorEnd="\033[0m"
[ $# -eq 0 ] && { echo "Usage: `basename $0` Input your ip address " ; exit 10; }
ping -c1 -W2 $* > /dev/null && echo -e $Color "$* is up"$ColorEnd || echo -e $Color"$* is down"$ColorEnd
标签:let ali The dom copyright bashrc img user 自动
原文地址:https://www.cnblogs.com/alexlv/p/11984439.html