Thread: Can't automate IP script at login
**solved**
i'll post how solved it, might in future
script running, couldn't find macsip file contains ip addresses, i'm assuming because script ran root , file stored in user dir.
ah well.
************
title maybe isn't great. script assigns ip based on mac address, have perl script , basic shell script test if can either work. i've tried starting them in several different ways, startup applications, rc.local , upstarts.
both scripts work fine if they're executed terminal when i'm logged in, getting them when user logs in seems problem. know can these scripts in other ways, such dhcp method need.
conclusion is, network manager, or network connections seems called starting after script executes overriding script. may seem obvious may wrong, don't know enough , i'm going mad trying work out. reason think because entered sleep command of 2 minutes , tried 4 minutes , sure startup delayed on reboot, know happening .
i've ran startup applications using xterm, left sudo command in script , worked, in sense script did start , asked sudo password, entering password fine script doesn't work; again leading me believe beginning of script has been executed early.
know if i'm going in wrong direction or have might able me with. don't need dhcp or can disabled if needs be. here scripts if helps.
perl script read macsip file, find mac , use ip it, works fine if run terminal. other script i've been using testing see if it's dodgy perl.
appreciated @ point.
the macsip file:code:#!/usr/bin/perl # #script set ip based on mac address. # #use warnings; use strict; # #global variables #sleep 120; @mac = (); @eth = (); @nameserver = ("192.168.19.254","192.168.19.253"); # $ipadd = ""; $host = ""; $currentmac = ""; $interface = ""; $mask = "255.255.255.0"; $gateway = "192.168.19.254"; # #for loop mac addresses - push these mac array (my $i=0; $i<5; $i++){ #get current macs $rec = `/sbin/ifconfig eth$i | grep "hwaddr"`; ($eth, $field2, $field3, $field4, $cmac) = split(/\s+/, $rec); push (@mac, "$cmac"); push (@eth, "$eth"); } #parse macsip file, if mac mataches assign hostname , ip address variable. #open file containing macs open (file, 'macsip'); while (<file>){ chomp;#chomp whitespace ($temphostname, $tempmac, $tempip) = split("\t"); (my $i=0; $i<5; $i++){ if($mac[$i] eq $tempmac){ $ipadd = $tempip; $host = $temphostname; $currentmac = $mac[$i]; $interface = $eth[$i]; goto end;#if mac mathces before 5, break loop } } } end:#end mac address. close (file);#close file containing macs # #kill dhcp, assign ip, gateway , dns. system "killall dhclinet"; system `sudo ifconfig $interface $ipadd netmask $mask`; #system "sudo ip route add default via $gateway"; # open ( dns, ">resolv.tmp"); print dns "nameserver $nameserver[0]\n"; print dns "nameserver $nameserver[1]\n"; close (dns); system "sudo mv resolv.tmp /etc/resolv.conf"; # system "sudo /etc/init.d/networking restart";
and test shell script:code:pc1 08:00:27:16:4a:0d 192.168.19.223 pc2 08:00:27:f9:fd:96 192.168.19.2 pc3 00:11:22:33:44:55 192.168.19.3 pctest 08:00:27:57:ab:b3 192.168.19.19
code:#!/bin/sh #bobby basic script change ip address. #mac addresses each system pc1mac="08:00:27:16:4a:0d" pc2mac="08:00:27:f9:fd:96" pc3mac="00:11:22:33:44:55" #get current mac eth0 cmac=`ifconfig | grep 'eth0' | tr -s ' ' | cut -d ' ' -f5` #check current mac against each system - assign ipadd variable required ip if [ $cmac = $pc1mac ] ipadd=192.168.1.1 fi if [ $cmac = $pc2mac ] ipadd=192.168.1.2 fi if [ $cmac = $pc3mac ] ipadd=192.168.1.3 fi #kill dhcp, assign ip, gateway , dns. killall dhclinet sudo ifconfig eth0 $ipadd netmask 255.255.255.0 sudo route add default gw 192.168.1.254 echo "nameserver 192.168.1.254" >> resolv.tmp sudo mv resolv.tmp /etc/resolv.conf sed '/^options.*/d' /etc/resolv.conf >>resolv.tmp echo "options retrans:1 retry:1" >> resolv.tmp sudo mv resolv.tmp /etc/resolv.conf sudo /etc/init.d/networking restart
how did solve problem??
have posted.
Forum The Ubuntu Forum Community Ubuntu Official Flavours Support Networking & Wireless [ubuntu] Can't automate IP script at login
Ubuntu
Comments
Post a Comment