kill httpd #===>杀死apache进程然后进行测试
[root@oldboy-A scripts]# ps -ef|grep http|grep -v grep #===>http进程不存在了
[root@oldboy-A scripts]# sh judgeweb-while.sh #===>执行看结果,返回1表示存在http进程
1
1
1
=============以下是学生的不同语法脚本===============
#!/bin/bash
#filename:while1
httpdport=`ps -ef|grep http|grep -v grep|wc -l`
while true
do
if (( "$httpdport" > 0 )) #======这是(())的语法写法
then
echo "1"
else
echo "0"
fi
sleep 60
done
--------------------------------------------------
问题2、已知如下命令及返回结果,请问 echo $user 的返回的结果为( ).并解释为什么?
[oldboy@test ~]$ cat test.sh
user=`whoami`
[oldboy@test ~]$ sh test.sh
[oldboy@test ~]$ echo $user
(互动百科面试题)
--------------------------------------------------
问题3. 从ett.log文件中提取包含"WARNING"或"UNKNOWN",同时不包含"OK"的行,然后提取以":"分割的第 3个字段
WARNING:UNKNOWN:OK:CRITICAL
WARNING:UNKNOWN:NO:OLDBOY
WARNING:NO:OLDBOY:QINGYUN
UNKNOWN:OK:CRITICAL::CRITICAL
(百度面试题)
解答;
步骤一:
[root@oldboy-B scripts]# egrep "WARNING|UNKNOWN" ett.log
WARNING:UNKNOWN:OK:CRITICAL
WARNING:UNKNOWN:NO:OLDBOY
WARNING:NO:OLDBOY:QINGYUN
UNKNOWN:OK:CRITICAL::CRITICAL
步骤二:
[root@oldboy-B scripts]# egrep "WARNING|UNKNOWN" ett.log|grep -v OK
WARNING:UNKNOWN:NO:OLDBOY
WARNING:NO:OLDBOY:QINGYUN
步骤三:
方法1:
[root@oldboy-B scripts]# egrep "WARNING|UNKNOWN" ett.log|grep -v OK |awk -F ":" ''{print $3}''
NO
OLDBOY
方法2:
[root@oldboy-B scripts]# egrep "WARNING|UNKNOWN" ett.log|grep -v OK |cut -d: -f3
NO
OLDBOY
--------------------------------------------------
问题4.已知oldboy.txt内容为
i am oldboy! my qq number is 31333741
请把oldboy.txt中小写字母转换成的写字母
[root@oldboy-B scripts]# echo ''i am oldboy! my qq number is 31333741'' >oldboy.txt
法1:
[root@oldboy-B scripts]# cat oldboy.txt |tr a-z A-Z
I AM OLDBOY! MY QQ NUMBER IS 31333741
[root@oldboy-B scripts]# cat oldboy.txt |tr "a-z" "A-Z"
I AM OLDBOY! MY QQ NUMBER IS 31333741
[root@oldboy-B scripts]# cat oldboy.txt |tr "[a-z]" "[A-Z]"
I AM OLDBOY! MY QQ NUMBER IS 31333741
[root@oldboy-B scripts]# cat oldboy.txt |tr [a-z] [A-Z]
I AM OLDBOY! MY QQ NUMBER IS 31333741
[root@oldboy-B scripts]# cat oldboy.txt
i am oldboy! my qq number is 31333741
提示:上面为不同的写法,tr的命令很好用,建议大家好好总结下.
这里也分享一个老男孩曾经写的生产环境使用tr的一个函数脚本.记住tr命令很有用.
function check_web_url()
#检查URL
{
wait #====>wait函数,内容见下面.
echo ''检查url...!.''
for ((i=0; i<`echo ${#web_url_list[*]}`; i ))
do
judge=($(curl -I -s --connect-timeout 5 ${web_url_list[$i]}|head -1|tr "r" "n"))
if [[ "${judge[1]}" == ''200'' && & |