Hi everyone. I’m not much experienced with scripting, but did try to write a simple one, without luck yet. So here is the story. I’m trying run a virtualbox guest os on startup. However it doesn’t start because of some wiered network bridge problem. But I’ve found out, that if I open VirtualBox and apply again the current active nic, it does start. For some strange reason the nic name is changing almost every time on boot up. So what I’m trying to do with my script it is: find out the currently active nic name, for instance eth21, apply this settings to the VB guest machine and fire it up. Here is my script
#!/bin/sh
sleep 60
date >> xp_started
str1=$(ifconfig |grep eth)
spacepos=$(echo `expr index "$str" " "`)
str2=${str1:0:$spacepos}
VBoxManage modifyvm xp --bridgeadapter1 $str2
VBoxManage startvm xp --type headless
If I execute each of the command in the terminal it looks ok, however running the script via sh -x scriptname tells me that spacepos equals to 0 and therfore it can not proceed to copy the string in next command. Please help, thanks
One question (no need to answer me). You seem to know the $( … ) construct. Why then do you use the old fashioned, only there for compatability ... around the expr statement?
One question (no need to answer me). You seem to know the $( … ) construct. Why then do you use the old fashioned, only there for compatability ... around the expr statement?
I don’t know much about scripting yet :shame:, that’s the best I could write with help of “google friend”
Eth should not keep changing numbers. Something is wrong with your setup.
Probably there is something wrong, I remember it all started when I wanted to have static ip instead of dhcp , anyway as far as it works, I won’t try to fix it
And you should learn to use cut or awk to get the first field out of the output of ifconfig. E.g.
uf, that really looks much easier, I’ll remember this one, thanks.
And without awk (to avoid the execution of an extra process):
ifconfig | grep eth | read ethinterface skip
And changing this one
spacepos=$(echo `expr index "$str" " "`)
into
spacepos=$(echo $(expr index "$str" " "))
is what I mean. The $( … ) is a replacment (since more then 20 years) for .... Much easier to read, can be nested (as you see). The mixture of both is curious to see.
I would use AWK, it’s more concise and in my opinion easier to read, this makes it less prone to mistakes, and as we all know, once the programs/scripts get less trivial, the fewer potential mistakes, the better.
I only really use SED if I want to store the output in a file, maybe I should spend some time learning more about it.
O yes, thank you for this. They did a really good job. And it is really nicely told. I do feel the stress while reading.
The thing is, that after such an exersize everybody is realy satisfied (and rightly so) with what is achieved and the wonderfull cooperation that goes with it. But it is always very difficult to recap what excact steps were taken during that night (such things usualy happen at the darkest hours).
Yes I love it, remembers me of some difficult, but wonderfull recoveries in my own carreer.
Yes, Linux users have it so much easier now, rescue CDs, extra machines to move the disk to, etc. None of this palaver with typing in hex code. But those three words must never be forgotten: backup, backup, backup.