- 1、本文档共28页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
shell常见问题
非常好的十道 HYPERLINK /os/linux/ \t _blank Linux?shell脚本面试题
?
1、编写个shell脚本将当前目录下大于10K的文件转移到/tmp目录下
?
#/bin/sh
?
#Programm :
?
# Using for move currently directory to /tmp
?
for FileName in `ls -l | awk $510240 {print $9}`
?
do
?
mv $FileName /tmp
?
done
?
ls -al /tmp
?
echo Done!
?
2、编写shell脚本获取本机的网络地址。
?
比如:本机的ip地址是:/,那么它的网络地址是
?
/
?
方法一:
?
#!/bin/bash
?
#This script print ip and network
?
file=/etc/sysconfig/network-scripts/ifcfg-eth0
?
if [ -f $file ] ;then
?
IP=`grep IPADDR $file|awk -F= { print $2 }`
?
MASK=`grep NETMASK $file|awk -F= { print $2 }`
?
echo $IP/$MASK
?
exit 1
?
fi
?
方法二:
?
#!/bin/bash
?
#This programm will printf ip/network
?
#
?
IP=`ifconfig eth0 |grep inet |sed s/^.*addr://g|sed s/ Bcast.*$//g`
?
NETMASK=`ifconfig eth0 |grep inet |sed s/^.*Mask://g`
?
echo $IP/$NETMASK
?
exit
?
3、用Shell HYPERLINK /kf \t _blank 编程,判断一文件是不是字符设备文件,如果是将其拷贝到 /dev 目录下。
?
参考程序:
?
#!/bin/sh
?
FILENAME=
?
echo “Input file name:”
?
read FILENAME
?
if [ -c $FILENAME ]
?
then
?
cp $FILENAME /dev
?
fi
?
4.请为下列shell程序添加注释,并说明程序的功能和调用方法:
?
#!/bin/sh
?
#
?
# /etc/rc.d/rc.httpd
?
#
?
# Start/stop/restart the Apache web server.
?
#
?
# To make Apache start automatically at boot, make this
?
# file executable: chmod 755 /etc/rc.d/rc.httpd
?
#
?
case $1 in
?
start)
?
/usr/sbin/apachectl start ;;
?
stop)
?
/usr/sbin/apachectl stop ;;
?
restart)
?
/usr/sbin/apachectl restart ;;
?
*)
?
echo usage $0 start|stop|restart ;;
?
esac
?
参考答案:
?
(1)程序注释
?
#!/bin/sh 定义实用的shell
?
#
?
# /etc/rc.d/rc.httpd 注释行,凡是以星号开始的行均为注释行。
?
#
?
# Start/stop/restart the Apache web server.
?
#
?
# To make Apache start automatically at boot, make this
?
# file executable: chmod 755 /etc/rc.d/rc.httpd
?
#
?
case $1 in #case结构开始,判断“位置参数”决定执行的操作。本程序携带一个“位置参数”,即$1
?
start) #若位置参数为start
?
/usr/sbin/apachectl start ;; #启动httpd进程
?
stop) #若位置参数为stop
?
/usr/sbin/apachectl stop ;; #关闭httpd进程
?
restart) #若位置参数为stop
?
/usr/sbin/apachectl restart ;; #重新启动httpd进程
?
*) #若位置参数不是start、stop或restart时
?
echo usage $0 start|sto
文档评论(0)