天天看点

shell编程中的常用语句 for,while语句

??????for??????

1,for????????????

for NUM in 1 2 3
for NUM in {1..3}
for NUM in `seq 1 3`  
for NUM in {a..f}
for NUM in {1..$a} ???????????????a???????????????????????????????????????export??????????????????????????????????????????
for ((A=1;A<=10;A++))
for NUM in `seq 1 2 10` 2????????????????????????????????????1
           

for NAME in westos linux 666 ???????????????echo $NAME????????????westos linux 666

?????????

exit?????????????????????

break?????????????????????????????????????????????????????????

continue?????????????????????????????????????????????

return???????????????

for????????????????????????????????????for?????????????????????for?????????

shell????????????

1,?????????????????????????????????

shell编程中的常用语句 for,while语句

###??????????????????????????????ip??????????????????????????????

??????

shell编程中的常用语句 for,while语句
shell编程中的常用语句 for,while语句
shell编程中的常用语句 for,while语句

2,???????????????linux,mysql,test,,westos???????????????/mnt/maysql_backup??????

[[email??protected] mnt]# mysql -uroot -EN -e "show databases;"
*************************** 1. row ***************************
information_schema
*************************** 2. row ***************************
linux
*************************** 3. row ***************************
mysql
*************************** 4. row ***************************
performance_schema
*************************** 5. row ***************************
test
*************************** 6. row ***************************
westos
           
shell编程中的常用语句 for,while语句
#!/bin/bash
DATABASE_MESSAGE=`mysql -uroot -EN -e "show databases;" | grep -E "^\*|schema$" -v` ?? ?? ?????????*?????????schema???????????? \???*??????
mkdir -p /mnt/mysql_dump
for DATABASE_NAME in $DATABASE_MESSAGE ?? ?? ?? ?? ???????????????????????????????????$DATABASE_MESSAGE????????????linux,mysql,test,westos???????????????DATABASE_NAME
do
	mysqldump -uroot $DATABASE_NAME > /mnt/mysql_dump/${DATABASE_NAME}.sql
	[ "$?" -eq "0" ] && {
		echo -e "\033[47m$DATABASE_NAME is backuped \033[0m"
	}
done
           

??????

shell编程中的常用语句 for,while语句

???????????????

?????????????????????for DATABSE_NAME in $DATABASE_MESSAGE??????????????????????????????DATABASE_MESSAGE???????????????????????????????????????????????????????????????????????????????????????????????????????????????for?????????????????????????????????????????????userfile????????????????????????for NAME in `cat userfile`!!!

??????while??????

1?????????

while ??????

do

done

shell????????????

uptime????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1?????????5?????????15???????????????????????????

??????whiel????????????uptime

shell编程中的常用语句 for,while语句

####sleep???????????? echo -n???????????????

??????

shell编程中的常用语句 for,while语句

???????????????

####??????????????????

[[email??protected] ~]# echo hello world | mail -s "nihao" root ?????????????? -s???????????????nihao
You have mail in /var/spool/mail/root
[[email??protected] ~]# mail ?? ?? ?? ?? ?? ?? ?? ?? ????????????
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 2 messages 1 new
    1 root                  Thu Jun 21 13:31  21/768   "nihao"
>N  2 root                  Thu Jun 21 13:31  20/757   "nihao"
& 
Message  2:
From [email??protected]  Thu Jun 21 13:31:52 2018
Return-Path: <[email??protected]>
From: root <[email??protected]>
Date: Thu, 21 Jun 2018 13:31:52 -0400
To: [email??protected]
Subject: nihao
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
Status: R

hello world ????????????
           

shell????????????

??????????????????????????????80%??????root?????????????????????

shell编程中的常用语句 for,while语句
#!/bin/bash
DISK_NUM=`df | awk '/\/$/{print $5}' | awk -F "%" '{print $1}'` ?? \/??????\??????????????????/??????????????????5???????????????%??????????????????????????????
while true
do
        [ "$DISK_NUM" -ge "80" ] && { ?? ?? ????????????80??????
                echo "Your / will full !!! " | mail -s "warning" root
        }
        sleep 1 ?? ?? ??????1????????????while??????
done
           

??????

shell编程中的常用语句 for,while语句
shell编程中的常用语句 for,while语句

?????????????????????

shell????????????

??????????????????????????????80%??????????????????????????????

[[email??protected] ~]# ps
  PID TTY          TIME CMD
 3645 pts/1    00:00:00 bash
 8101 pts/1    00:00:00 ps
[roo[email??protected] ~]# ps | awk '/bash$/{print $2}' ?? ??????????????tty??????
pts/1
           
shell编程中的常用语句 for,while语句

####??????????????????????????????

??????

shell编程中的常用语句 for,while语句

???????????????