Basic script attempt

Try the script for the first time. Go by and correct it!

syeteminfo system profile command

   #!/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`"

After execution, the machine configuration information is displayed.       


Create apache user command

    #!/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!"

After execution, you can create user apache according to the above requirements.
        

Change command line color

    #!/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

After execution, the command line color of root will turn yellow.     


Make a file to add the execution command

    #!/bin/bash
    #Description:Add execution permissions to the file  
    #filename:ex.sh
    chmod +x $1
    echo $1 can be excute

To execute a command, simply enter the file name followed by the command to add permissions.     

 

Make a quick file to Dadda's computer

    #!/bin/bash
    #Description:connect Handsome Dadda'computer 
    #filename:cdadda.sh
    scp $* Dadda@172.16.0.6:

The execution can be transferred to Dadda host by entering the name followed by the file name.   

Create any user with a password of Dadda and the password modification process is not seen. Force to change the password the next time you log in

    #!/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!

To execute, just enter the command followed by the user name you want to create, and create successfully.    

Fill in basic information automatically when creating script

    #!/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

When executing, you only need to enter the command followed by the name of the script file to be created and create it successfully.
 

 

Tags: Apache network shell vim

Posted on Sun, 12 Jan 2020 12:44:42 -0500 by amedhussaini