1, create a user script
#!/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"
Notes: * For $ System variable, $ COLOR and $ COLOREND custom variables, want to change the color of the display can be easily modified.
2, copy files to another machine
#!/bin/bash
#**************************************************************
COLOR='\033[1;32m'
COLOREND='\033[0m'
echo -e "$COLOR 'start'$COLOREND"
scp -r $* [email protected]:/data/
echo -e "$COLOR 'over'$CLOOREND"
Notes: user.sh for the file name, add -r can transfer files can also pass folder
3, delete instead moved to a folder
#!/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"
Note: The script alias rm = '/ data / scripts37 / rm.sh' defined alias rm equal just created, execute scripts automatically execute rm
Define aliases place entered directly under the root directory vim .bashrc, or enter vim in whatever directory ~ / .bashrc
$ [RANDOM% 7 + 31 Random Color
4, calculate the preparation of chickens and rabbits with cage
#!/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
Note: $ [RANDOM% 7 + 31 Random Color
5, ping script writing
#!/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