第三周作业
1
#cp /etc/profile /tmp
%s/^[[:space:]]\+//
2
set tabstop=4
3
4
if `id $USERNAME &> /dev/null`;then
echo "用户存在,用户的ID信息为:`id $USERNAME`"
else
PASSWORD=`cat /dev/urandom |tr -cd [:alpha:] |head -c8`
`useradd $USERNAME &> /dev/null`
`echo "$PASSWORD" | passwd --stdin $USERNAME &> /dev/null`
echo "用户名:$USERNAME 密码: $PASSWORD" >> user.txt
`chage -d 0 $USERNAME`
echo "用户已添加,用户的ID信息为:`id $USERNAME` 密码为:$PASSWORD"
fi
5
vim systeminfo.sh
BEGINCOLOR="\e[1;35m"
ENDCOLOR="\e[0m"
echo -e "My hostname is ${BEGINCOLOR}`hostname`$ENDCOLOR"
echo -e "IP address is ${BEGINCOLOR}`ifconfig eth0 |grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1`$ENDCOLOR"
echo -e "OS version is ${BEGINCOLOR}`cat /etc/redhat-release`$ENDCOLOR"
echo -e "Kernel version is ${BEGINCOLOR}`uname -r`$ENDCOLOR"
echo -e "CPU type is ${BEGINCOLOR}`lscpu|grep "Model name" |cut -d: -f2 |tr -s " "`$ENDCOLOR"
echo -e "Memtotol is ${BEGINCOLOR}`cat /proc/meminfo |head -n1 |grep -Eo '[0-9]+.*'`$ENDCOLOR"
echo -e "Disk space is ${BEGINCOLOR}`lsblk |grep 'sda\>'|grep -Eo '[0-9]+[[:upper:]]'`$ENDCOLOR"
6
#! /bin/bash
BEGIN="\e[1;35m"
END="\e[0m"
echo -e "${BEGIN}`df | grep /dev/sda | grep -o '[0-9]\+%'`${END}"

浙公网安备 33010602011771号