-
another idea....
I have an idea to further improve this script.....
#!/bin/sh
konsole -e telnet n7us.net
This script assumes there is a valid internet connection
I ran the script with the network cable pulled out of side of computer....it brings up the Konsole, but just sits there with blank screen.......
Just to make the script nicer, is there a way to test for network connection, if there is, the script just runs as normal. But if there is no connection, the script just exits, and that way, you dont have a blank Konsole screen staring at you. Not that its a big deal, but I think this would be a nicer script.
I am reading up on linux shell scripts but its hard to find the right command for the job. Would you use an if command? Not sure of syntax......bob
-
You could use an if/then/else pair in your script. For example:
Code:
if eth0 up
then exec telnet-ssl session
else exit
This isn't actual code but just a layout so you get the idea for error-proofing the script. The else statement catches anything that doesn't apply to the if statement, otherwise it would trigger the telnet-ssl session and exit when the session is done.
HTH,
Durand
-
if/then/else
Hello Durand......I will try what you suggested. The script i am usingis below:
#!/bin/sh
konsole -e telnet n7us.ne
But where would i insert this coding? :
if eth0 up
then exec telnet-ssl session
else exit
Would I put it right after the last line in my script? I posted a separate message about getting scripting help for different things. I have also been reading the help sites on web but cannot really find what I want. I want to understand the code you suggested and learn what each line does. I will try this and post backlater my results....bob
-
Found something on the net for you:
Code:
#!/bin/sh
NET=eth0
if ! ifconfig | grep $NET >/dev/null 2>&1 ||\
! ifconfig $NET | grep UP >/dev/null 2>&1; then
echo "Get a net!"
exit 1
fi
konsole -e telnet n7us.ne
exit 0
-
Try this block as your script:
Code:
#!/bin/sh
if [-e /etc/network/ifstate ]
then konsole -e telnet
else exit
exit
fi
That should be all it should take. Upon perusing the other scripts with this type of block, it seems that you must end an if statement with fi. Note I inserted two exits, one to catch if the eth0 connection isn't up, and the other to terminate the script once the telnet session is done. This way you wouldn't have to create two scripts when one like this would kill two birds with one stone.
HTH,
Durand
-
thanks
thanks Duran and Markus......I will try the scripts later tonite and see what happens.....a few questions tho.....for Markus...that coding sure looks complicated! How would I go about deciphering it? I would l;ike to know what the script line by line does if possible. And Durand, in your script i didnt see a reference to the "n7us.net" that I connect with. OK i will try out ad post back tomorrow....thank you..bob
-
Hehe, As I said I found it on the net and modified just a bit, just can't get used to not declaring a variable before using it which you don't seem to have to do in bash.
Basically it looks for the word eth0 in ifconfig and directs the stderr output to the same filedescriptor as stdout, don't ask me how: http://en.tldp.org/HOWTO/Bash-Prog-I...O-3.html#ss3.1
If it can't find eth0 it echos a message and exits, if it finds it you get a connection and it exits afterwards.
-
Hmm, Durands approach seems a bit easier, how about:
Code:
#!/bin/sh
NET=$(grep eth /etc/network/ifstate)
if [ -n "$NET" ]
then
konsole -e telnet n7us.ne
exit 1
else
echo "Get a net!"
exit 0
fi
If eth0 is found in /etc/network/ifstate NET gets the value eth0=eth0, then -n tests if the variable NET is not empty and proceeds with telnet, else echoes a message.
Hmm again. His block is still shorter :( :wink:
-
A different approach would be to look if n7us.net is availabĺe:
Code:
ping -c1 n7us.net >/dev/null 2>&1 && echo success
or
Code:
ping -c1 n7us.net >/dev/null 2>&1 || exit 1
eth0 may be up in the local net.
may be up, but no dns-server found ...
-c1 will only ping one time.
>/dev/null sends the output to 'nowhere'
2>&1 sends errormessage to the location, where the output goes ('nowhere' too)
&& (read: AND) will execute the following code only if the first command succeeded. Here you may call a script-function, if your command is too complex.
|| (read: OR [exclusive]) will execute the following command (exit 1) only, if the previous failed.
So your code for continuing when everything is fine will just follow.
In general, an excellent scripting guide is found here:
http://freshmeat.net/projects/advanc...criptingguide/
Do you want to run the script totally automated?
If you want to login, where you have to wait for a login-prompt, you have to use 'expect' - which isn't installed on my system - why?
-
(sorry - doubled 'submit'-hit)