LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Fedora (https://www.linuxquestions.org/questions/fedora-35/)
-   -   Startup Script Output (https://www.linuxquestions.org/questions/fedora-35/startup-script-output-782402/)

Mordocai 01-15-2010 09:57 AM

Startup Script Output
 
I am using fedora 12 to attempt to create a liveCD that will boot up, output the MAC addresses of the system, and then pause. I have a script that does this, but when I add it to /etc/rc.d/rc.local it does not output to the screen, though it does run. I am using run level 3. Is there any way to do this? Worst case scenario, we'll just have to type a command to run it after the CD boots.

P.S. This may seem pointless, but it is because one of our departments needs to record the MAC addresses of every new system, while a different one installs an OS. They come with windows but it takes forever to start up for the first time.

EDIT: And yes, the BIOS shows the ethernet MAC address, but we also need the bluetooth and wireless

affinity 01-15-2010 10:54 AM

Can you post the script? I'm not sure about the pause, but using the echo command would display the output. You could make the script mount a thumb drive and store the output to a file on it. If you wanted it to be organized you could have the script create a directory on the thumb drive using an identifier for that computer, it's host name or something else that is unique, and then store the MAC addresses in a file in that directory.

Mordocai 01-15-2010 11:07 AM

Well, the current method is to just write the mac address down with all the other info on the PC(Serial number, model number, etc) and then enter it all into spreadsheets. Everything works properly if simply executed, i'm just hoping to make it automatic since most of the people doing this have little to no knowledge of linux.

EDIT: The reason i know it runs is that the script successfully downloads macFetch-online.sh from the server.

NOTE: I'm not sure if i need to add the iwconfig output to the file in order for the script to work. I am currently testing in virtual machines, and have not tested on a machine with wireless yet.

This is what the rc.local looks like:
Code:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
/MacFetch/macFetch-startup.sh
touch /var/lock/subsys/local

This is the code that the startup file has in it:

Code:

#!/bin/bash

#try to grab the networked script
cd /MacFetch/
wget -q  http://<path-to-server>/macFetch-online.sh

#Check and see if it worked
if [ -f /MacFetch/macFetch-online.sh ]; then
        chmod +x /MacFetch/macFetch-online.sh
        /MacFetch/macFetch-online.sh
else
        /MacFetch/macFetch-local.sh
fi

This is the code that is supposed to run:
Code:

#!/bin/bash



#Set the temporary file used for this script
FILE="networkInformation.txt"
BLUEFILE="bluetoothInfo.txt"

#Get the network info and put into the file
ifconfig | grep HWaddr > $FILE
iwconfig | grep HWaddr >> $FILE
hcitool dev | grep hci > $BLUEFILE

#Formatting
echo "Interfaces    MAC Addresses"

#Go through every line in the file
#Find the interface name and MAC address
#Output with formatting
while read line
        do

                ETH=`echo $line | cut -d \  -f 1`
                HWADDR=`echo $line | cut -d \  -f 5`
                echo $ETH "        " $HWADDR

        done < $FILE

#Do the same for bluetooth
while read line
        do
                IF=`echo $line | cut -d \  -f 1`
                HWADDR=`echo $line | cut -d \  -f 5`
                echo $IF "        " $HWADDR

        done < $BLUEFILE

#remove the files
rm -f $FILE $BLUEFILE

read -n 1 -p "Press any key to continue..."


affinity 01-15-2010 11:55 AM

What I would do if you are physically going to each computer to run the script is make a bootable thumb drive with the script already stored on it. Set it up so that it automatically logs into a default account without having to use a password, and then have the script stored in the /home directory. That way the person doing this could literally just plug the drive in, turn on the computer, and then execute the script. Have you thought about doing this remotely after all the computers are already running? It would save a lot of time, and be much simpler, if it was possible for you to execute the script on all the computers in the network from another computer and have it store the data in an organized fashion. Then you could just execute the script once and give the files to whoever has to put them into a spreadsheet.

As for the script itself, ifconfig will list the HWaddr of all the interfaces, including wireless. The iwconfig command only displays information about the current connection itself.

Mordocai 01-15-2010 12:33 PM

Well, I'm rather low on the food chain here, and was assigned this project. They opted to use CDs so that they could make many copies cheaper than buying a lot of flash drives. I will, however, look into seeing if we can get the mac addresses remotely. The thing is, even our build system, Altiris, is set up to use the MAC addresses. Therefore, we have to have them before we can do much of anything. In any case, the basic functionality appears to be fine, i was just wondering whether I could get the script to start up at boot time, that way they put in the CD, turn on the computer, and come back a minute later and the MAC addresses are up on the screen. If this isn't possible, it isn't a big deal. I do know, however, that I saw it done on knoppix, but I don't know how.

affinity 01-15-2010 01:04 PM

The script can be run at boot time the way you had it set up, your original problem was having it pause for the output. I would have the script itself on the disc so it doesn't have to fetch it off the server. Then, as to your original problem, I would have the script be the very last thing that is run using the echo statement to print each result. If all goes well you would see the MAC addresses above the login prompt.

Mordocai 01-15-2010 03:03 PM

Okay, I figured out that the script was in fact running, but it was "hidden" by the graphical loading screen. To get around this I set up an autologin and set the user's .bash_profile to run the script on login.


All times are GMT -5. The time now is 05:32 AM.