shell脚本中的ifconfig,无法在Linux RedHat启动时运行 [英] Ifconfig in shell script, not able to run on startup of Linux RedHat

查看:518
本文介绍了shell脚本中的ifconfig,无法在Linux RedHat启动时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行编写了"ifconfig"命令并​​将输出放置到另一个文件的shell脚本.

实际上,我们不知道机器的IP地址,我们已经在上面部署了Linux.我们想知道机器启动后的IP地址.因此在启动时,它将使用ifconfig输出创建一个文件,因此我们可以读取ip地址.

代码:

I want to run shell script which has "ifconfig" command written and placing output to another file.

Actually we dont know the ip address of the machine, we have deployed Linux on it. we want to know IP address of that machine once it gets boot up. so on boot up it will create one file with ifconfig output, so we can read ip address.

code:

hostname=$(hostname)

#mount shared drive
mount -t cifs -o username= ,password= //111.111.111.111/MLC /mnt

#delete file if it already exists locally
if [ -f /$hostname.txt ];
then
	rm -f /$hostname.txt
fi

#delete file if it exists in the share
if [ -f /mnt/$hostname.txt ];
then
	rm -f /mnt/$hostname.txt
fi

#create new file
touch $hostname.txt
#redirect ip details to the file
ifconfig>$hostname.txt
#copy to the mounted share
cp /$hostname.txt /mnt/$hostname.txt
#unmount
umount /mnt




我能够在启动时运行其他命令,但不仅可以运行ipconfig命令.

有人帮我吗?

谢谢




i am able to run other commands in startup, but not only ipconfig command.

does anybody help me?

Thanks

推荐答案

(主机名) #mount共享驱动器 mount -t cifs -o username =,密码=//111.111.111.111/MLC/mnt #删除文件(如果已在本地存在) 如果[-f/
(hostname) #mount shared drive mount -t cifs -o username= ,password= //111.111.111.111/MLC /mnt #delete file if it already exists locally if [ -f /


hostname.txt]; 然后 rm -f/
hostname.txt ]; then rm -f /


hostname.txt 科幻 #删除文件(如果存在于共享中) 如果[-f/mnt/
hostname.txt fi #delete file if it exists in the share if [ -f /mnt/


这篇关于shell脚本中的ifconfig,无法在Linux RedHat启动时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆