Click here to Skip to main content
15,860,972 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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



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

does anybody help me?

Thanks
Posted
Updated 2-Oct-12 21:49pm
v3
Comments
Richard MacCutchan 2-Oct-12 9:12am    
Without some more detail it is impossible to guess what is happening. Please edit your question and show the command that you are trying to run and any output from the script.
skydger 3-Oct-12 3:10am    
Is it possible that your script's work starts when net interface is not initialized yet?
[no name] 3-Oct-12 3:56am    
No its not the case, because before that we are mounting with IP address.
Richard MacCutchan 3-Oct-12 4:28am    
What happens when you run ifconfig manually, what output do you see? Also what does get written into the $hostname.txt file?
[no name] 3-Oct-12 4:53am    
it works properly when i run it manually.
and it gives output like

eth1 Link encap:Ethernet HWaddr 00:50:56:AF:0D:35
inet addr:10.94.103.171 Bcast:10.94.103.255 Mask:255.255.255.128
inet6 addr: fe80::250:56ff:feaf:d35/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:65 errors:0 dropped:0 overruns:0 frame:0
TX packets:112 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8809 (8.6 KiB) TX bytes:13998 (13.6 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:14 errors:0 dropped:0 overruns:0 frame:0
TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:824 (824.0 b) TX bytes:824 (824.0 b)

so i can extract ip address from this.

but not at machine start ups.

1 solution

If you have no any other interfaces except these two listed above, then I suggest you to check your script using full path to ifconfig. I assume it is /sbin/ifconfig. Maybe the PATH environment variable does not contain /sbin at script running time or there are too few rights to execute it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900