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.

#!/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

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.

# 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 ?