In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Write hello world scripts
#! / bin/bash
Echo "hello world"
Create Linux system account and password through location variable
#! / bin/bash
# $1 is the first parameter for executing the script, and $2 is the second parameter for executing the script
Useradd "$!"
Echo "$2" | passwd-- stdin "$2"
Use the tar command to back up all log files under / var/log every 5 days
# vim / root/logbak.sh
# write a backup script, and the file name after the backup contains a date label to prevent subsequent backups from overwriting the previous backup data
# Note that the date command needs to be enclosed in backquotes, which are above the keyboard keys
Tar-czf log-date +% Y%m%d.tar.gz / var/logcrontab-e # write scheduled tasks and execute backup scripts
00 03 5 / root/logbak.sh
One-click deployment of LNMP (RPM package version)
#! / bin/bash
# to install and deploy LNMP using yum, you need to configure the yum source in advance, otherwise the script will fail
# script for centos7.2 or RHEL7.2
Yum-y install httpd
Yum-y install mariadb mariadb-devel mariadb-server
Yum-y install php php-mysql
Systemctl start httpd mariadb
Systemctl enable httpd mariadb
Real-time monitor the local memory and the remaining space of the hard disk. The remaining memory is less than 500m and the remaining space of the root partition is less than 1000m.
Send an alarm email to the root administrator when
#! / bin/bash
# Author: Jacob
# extract the remaining space in the root partition
Disk_size=$ (df / | awk'/\ / {print $4}')
# extract the remaining memory space
Mem_size=$ (free | awk'/ Mem/ {print $4}')
While:
Do
# Note that the amount of memory and disk space extracted is in Kb.
If [$disk_size-le 512000-a $mem_size-le 1024000]; then
Mail-s Warning root / dev/null
If [$?-eq 0]; then
Echo "192.168.4.Secreti is up"
Else
Echo "192.168.4.Secreti is down"
Fi
Let iTunes +
Done
Write a script to test which hosts are powered on and which hosts are powered off in the entire network segment of 192.168.4.0
Status (multi-process version)
#! / bin/bash
# Author: Jacob
# define a function to ping a host and check the survival status of the host
Myping () {
Ping-c2-i0.3-W1 $1 & > / dev/null
If [$?-eq 0]; then
Echo "$1 is up"
Else
Echo "$1 is down"
Fi
}
For i in {1..254}
Do
Myping 192.168.4.
Done
# use the & symbol to put the executed function into the background for execution
# the advantage of this is that you can continue to concurrently ping the second host without waiting for a response from the first host of ping, and so on.
Write a script to display the progress bar
#! / bin/bash
Jindu () {
While:
Do
Echo-n'#'
Sleep 0.2
Done
}
Jindu &
Cp-a $1 $2
Killall $!
Echo "copy complete"
Progress bar, dynamic clockwise version
#! / bin/bash
# define a function that displays progress, which can be quickly displayed on the screen | / -\
Rotate_line () {
INTERVAL=0.1 # set the interval
COUNT= "0" # sets the number of 4 shapes, and the default number is 0 (does not represent any image)
While:
Do
COUNT=expr $COUNT + 1 # executes the loop, with COUNT adding 1 for each loop (representing different shapes in 4, respectively)
Case $COUNT in # judge the value of COUNT. If the value is different, the shape will be different.
"1") # with a value of 1 shows-
Echo-e'-'"\ b\ c"
Sleep $INTERVAL
("2") # the value is shown as 2, and the first\ is escaped
Echo-e'\'"\ b\ c"
Sleep $INTERVAL
("3") # values are displayed as 3 |
Echo-e "|\ b\ c"
Sleep $INTERVAL
"4") # value is 4 display /
Echo-e "/\ b\ c"
Sleep $INTERVAL
*) # reset COUNT to 0 when the value is other
COUNT= "0"
Esac
Done
}
Rotate_line
99 multiplication table (write shell script, print 99 multiplication table)
#! / bin/bash
For i in seq 9
Do
For j in seq $I
Do
Echo-n "$ifuj $[ij]"
Done
Echo
Done
Real-time display of packet traffic sent by eth0 Nic using an endless loop
#! / bin/bash
# Author: Jacob
While:
Do
Echo 'local Nic eth0 traffic information is as follows:'
Ifconfig eth0 | grep "RX pack" | awk'{print $5}'
Ifconfig eth0 | grep "TX pack" | awk'{print $5}'
Sleep 1
Done
Using the personnel list in the user.txt file, automatically create the corresponding account on the computer and configure the initial password
#! / bin/bash
# to execute this script, you need to prepare a user.txt file in advance, which contains several user name information
For i in cat user.txt
Do
Useradd $I
Echo "123456" | passwd-- stdin $I
Done
Write scripts for batch modification of extension, such as batch modification of txt files to doc files
#! / bin/bash
# when executing a script, you need to add location parameters to the script
# script name txt doc (you can change the extension of txt to doc)
# script name doc jpg (you can change the extension of doc to jpg)
For i in "ls. $1"
Do
Mv $I ${I%.}. $2
Done
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.