初试脚本,往路过大神多多指正!
syeteminfo系统配置文件命令
#!/bin/bash
#Descrition:show system information
#filename:systeminfo.sh
echo "OS version is:`cat /etc/redhat-release`"
echo "kernel version is:`uname -r`"
echo "CPU type :`lscpu|grep 'Model name'|tr -s ' ' |cut -d: -f2`"
echo "`cat /proc/meminfo |head -n1`"
echo "`lsblk |grep '^sd'|tr -s ' ' |cut -d' ' -f1,4`"
echo "My username is $USER"
echo "My hostname is `hostname`"
echo "NETwork IP:`ifconfig ens33|grep -w 'inet'|grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1`"
执行后,即可显示机器配置信息。
创建apache用户命令
#!/bin/bash
#Description:Useradd-apache u-80 g-80 home-/var/www shell-/sbin/nologin
#filename:apache.sh
groupadd -g 80 apache
useradd -u 80 -g apache -s /sbin/nologin -d /var/www apache
echo "User apache is created"
mkdir -pv /var/www
chown -R apache:apache /var/www
echo "/var/www is ready!"
执行后即可按照以上要求创建用户apache。
更改命令行颜色
#!/bin/bash
#Description:change root's COMMOND line color (33=yellow)
#filename:env.sh
cat >> /root/.bash_profile <<EOF
PS1="\[\e[1;33m\][\u@\h \W]\\$\[\e[0m\]"
EOF
执行后root的命令行颜色即可变成黄色。
制作一个添加执行命令的文件
#!/bin/bash
#Description:Add execution permissions to the file
#filename:ex.sh
chmod +x $1
echo $1 can be excute
执行只需输入命令后面跟文件名,即可添加权限。
制作一个快速传到Dadda电脑的文件
#!/bin/bash
#Description:connect Handsome Dadda'computer
#filename:cdadda.sh
scp $* [email protected]:
执行只需输入命名后面跟文件名,即可传送到Dadda主机。
创建任意用户密码为Dadda且修改密码过程不被看到,下次登录时强制更改密码
#!/bin/bash
#Desscription:Create the user and change the password the next time use it.
#filename:createuser.sh
#create $1
useradd $1
echo $1 create success!
#for $1 create passwd --No Display
echo dadda | passwd --stdin $1 &>/dev/null
#change the password the next time No Display (or:chage -d filename)
passwd -e $1 &>/dev/null
echo $1 password is reset!
执行只需输入命令后跟要创建的用户名,及创建成功。
创建脚本时自动填写好基本信息
#!/bin/bash
name=Dadda_Du
qq=316722220
cat >$1 <<EOF
#!/bin/bash
#**************************************************************
#Author: $name
#QQ: $qq
#Date: `date +%F`
#FileName: $1
#URL: https://blog.csdn.net/weixin_40001704
#Description: The script test
#Copyright(C): 2018 all rights reserved
#**************************************************************
EOF
chmod +x $1
vim + $1
执行时只需输入命令后跟要创建的脚本文件名,及创建成功。