Computing.Net > Forums > Linux > shell script variable

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

shell script variable

Reply to Message Icon

Name: ged
Date: August 14, 2002 at 16:29:41 Pacific
Comment:

My desire is to have a random eight segment number automatically inserted in the last line b4 execution.

Here is what i mean ( i would like 999999999 to change to a random number everytime )

rm /etc/dhcpc/dhcpcd-eth0.info
rm /etc/dhcpc/dhcpcd-eth0.cache
/etc/sysconfig/network-scripts/ifdown eth0
/sbin/dhcpcd -I 99999999 eth0

any help would be appreciated



Sponsored Link
Ads by Google

Response Number 1
Name: junky_toof
Date: August 14, 2002 at 17:12:59 Pacific
Reply:

function intro_rand() {
i=0
mylist=""
while test $i -lt 8
do
i=`expr $i + 1`
r=`awk -v x="8" ' BEGIN {
srand()
print int(1 + rand() * x)
}'`
mylist="$mylist $r"
done
mylist=`echo $mylist | sed 's/[\t ]//g'`
export mylist
return
}
intro_rand && /sbin/dhcpcd -I $mylist eth0


0

Response Number 2
Name: dfx
Date: August 15, 2002 at 02:53:49 Pacific
Reply:

Here's my solution, couldn't resist ;)

R=""
for ((I = 0; I < 8; I++))
do
R=$R$(($RANDOM % 10))
done
/sbin/dhcpcd -I $R eth0


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: shell script variable

advanced shell script help www.computing.net/answers/linux/advanced-shell-script-help/17749.html

adding user options to shell script www.computing.net/answers/linux/adding-user-options-to-shell-script/19801.html

Shell Script - help www.computing.net/answers/linux/shell-script-help/21347.html