Visit Our UNIX and Linux User Community


Create a script to setup the network card


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Create a script to setup the network card
# 1  
Old 09-22-2009
Create a script to setup the network card

Hello!

Trying to build a script which will do the following:

1.) Due to continued stalling after each reboot will consider the uptime of the server and if it is less than 30 sec to load the following settings on your network.

essentially

2.) What interests me primarily is to make a script which only runs to enter the following settings on your network.

--ip
--netmask
--default gw
--key
--essid

or in one way or another.

Code:
#!/bin/bash

if [ uptime <= 30sec ] ; then
echo setup network card

        ifconfig wlan0 192.168.1.101 netmask 255.255.255.0 up;
        route add default gw 192.168.1.1;
        iwconfig wlan0 essid linksys;
        iwconfig wlan0 key 123abcd123;
fi

Can you help me;because this script does not work.

sorry for my bad english.

Now I saw the category shell programming so let's move a mod if you can

Last edited by anargi; 09-22-2009 at 05:29 PM..
# 2  
Old 09-23-2009
Quote:
Originally Posted by anargi
Hello!

Trying to build a script which will do the following:

1.) Due to continued stalling after each reboot will consider the uptime of the server and if it is less than 30 sec to load the following settings on your network.

essentially

2.) What interests me primarily is to make a script which only runs to enter the following settings on your network.

--ip
--netmask
--default gw
--key
--essid

or in one way or another.

Code:
...
if [ uptime <= 30sec ] ; then
...

shell comparisons do not work that way. Shell operations don't have a <= operator either, it's called "-le" for "less than or equal". Nor are you feeding the output of the uptime command into the comparison, you're just giving it the name of the command. And uptime doesn't report the system uptime in any manner the shell could sensibly compare it anyway, at least on my system.

My system has the file /proc/uptime which the system uptime can be read from in seconds. It has two decimal places, which will need to be removed for the shell to understand it as a number.

Code:
# We don't care about G, but if we only specify one variable here, it'll cram both numbers into one variable.
read A G < /proc/uptime
# Remove decimal point
A="${A/.*/}"
if [ "$A" -lt 30 ]
then
echo setup network card

        ifconfig wlan0 192.168.1.101 netmask 255.255.255.0 up
        route add default gw 192.168.1.1
        iwconfig wlan0 essid linksys
        iwconfig wlan0 key 123abcd123
fi

Also, you don't need semicolons at the end of a command unless you want to put more than one command on the same line.

Do you have static DNS servers set up in /etc/resolv.conf ?

Previous Thread | Next Thread
Test Your Knowledge in Computers #229
Difficulty: Easy
According to NetMarketShare, in September 2019 Linux had a 2% global market share of the desktop / laptop computer market.
True or False?

10 More Discussions You Might Find Interesting

1. Red Hat

Regarding Network Interface Card

Dear All , While taking backups in one Linux Server , we find one alert came with regard to Network Interface Card. Pl find the below alert. Network Interface Card performance for NIC:eth1 has exceeded Major threshold. Bytes sent and received per second (Average)= 105540.303101... (6 Replies)
Discussion started by: jegaraman
6 Replies

2. UNIX for Dummies Questions & Answers

How can I tell which network card is which?

I have three network cards in my unix box. I need to figure out which card corresponds to an assigned IP address. If there some command in unix I can use to make an ethernet interface blink? Any advice would be appreciated. (6 Replies)
Discussion started by: mojoman
6 Replies

3. IP Networking

network setup???

Hello everybody, I am a new unix user (Solaris 10). I was wondering if anybody can help me figure out how to connect to the network in my work place. I know my IP address, subnet mask, gateway, primary and secondary DNS addresses but I don't know how to enter these settings into my Solaris. ... (3 Replies)
Discussion started by: arash05
3 Replies

4. Solaris

network setup

on sparc solairs 2.8 which files i need to configure for network setup: /etc/hosts /etc/defaultrouter /etc/netmasks /et/resolv.conf what els?. by the way, how do i configure for rsh?. like for doing "rsh remotehostname date"?. (2 Replies)
Discussion started by: S26+
2 Replies

5. UNIX for Advanced & Expert Users

network card problem

hi, everyone: alpha 600 au true64 Unix 4.0f my network cart is set "Auto-Negotiate".After operate system startup,the network will be disconnected by itself at sometime. I found some prompt in /usr/adm/messages. "tu0 :transmit FIFO underflow:threshold raised to :256 byteŁ¬link up... (1 Reply)
Discussion started by: q30
1 Replies

6. UNIX for Advanced & Expert Users

Network Card Help

I have been having trouble with my sis900 neytwork card in slacwkare linux. I tried to modprobe the sis900, it didnt give me any errors but it didnt load it. so I put in a realtek 8139 network card and tried it too. These are the errors i get with the two cards when trying to do insmod on either of... (3 Replies)
Discussion started by: The Fridgerator
3 Replies

7. UNIX for Dummies Questions & Answers

Installing network card

1) i am trying to install realtek network card in caldrea linux, but i am not able to find the interface, 2)i download drivers for network card and i am not able to read the floopy in linux, pls help me out. (1 Reply)
Discussion started by: gops
1 Replies

8. IP Networking

Network Setup

I am moving a SUN 250 server from one location to another. The IP address has to change in order to make the server visible in the new building. The system administrator has given me the new IP address for the server, the DNS server IP and the default gateway IP. First question, is this all the... (2 Replies)
Discussion started by: pkappaz
2 Replies

9. Shell Programming and Scripting

Multiple Network Card Status Script

I have multiple Sun Solaris 8 systems running multiple network cards. (Mix of quad and gig cards.) What I would like to do is create a monitor script to ensure high availability of these cards. Has anyone ever had a situation like this? I was thinking of using the ping command, but am... (1 Reply)
Discussion started by: Krusty
1 Replies

10. IP Networking

network card

I have a UnixWare 2 server that has an ISA 3Com NIC that has just a BNC connector on it. I want to remove this and install an ISA 3Com NIC that has a BNC/RJ45 connector. What steps do I have to go through to successfully complete this? Thye are almost the exact same cards except for the... (1 Reply)
Discussion started by: cparks
1 Replies

Featured Tech Videos