-
Senior Member
registered user
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
-
Senior Member
registered user
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
-
Senior Member
registered user
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
-
Senior Member
registered user
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
-
Senior Member
registered user
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
-
Senior Member
registered user
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?
-
Senior Member
registered user
(sorry - doubled 'submit'-hit)
Similar Threads
-
By sunnmoon in forum General Support
Replies: 1
Last Post: 06-15-2005, 04:08 PM
-
By fmfischer in forum General Support
Replies: 1
Last Post: 04-14-2005, 11:07 AM
-
By irvine in forum The Lounge
Replies: 4
Last Post: 12-02-2004, 03:27 AM
-
By bikerman in forum General Support
Replies: 1
Last Post: 04-15-2004, 12:22 AM
-
By shadinio in forum Hardware & Booting
Replies: 1
Last Post: 03-25-2004, 09:09 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules

Gigabyte 4U AI Server 10x Nvidia GPU 2x Xeon Gold 6150 36 Core 2.7GHz DDR4 RAM
$1499.00

Dell EMC PowerEdge R440 Xeon silver 4215 2.5GHz 16 GB ram 2x 550W PSU No HDD
$275.00

Dell PowerEdge R240 Intel Xeon E-2224 3.50GHz 8GB DDR4 ECC NO HDD 250W
$285.97

867959-B21 HPE ProLiant DL360 G10 CTO Server W/ 2x 865414-B21 1x 840140-001
$245.00

Dell PowerEdge R730XD 28 Core Server 2X Xeon E5-2680 V4 H730 32GB RAM No HDD
$378.93

Dell PowerEdge C4130 1U AI GPU Server | 2x E5-2680 v3 | 32gb Ram | 2x 1600W
$409.99

Dell PowerEdge C4130 1U AI GPU Server | 2x E5-2690 v3 | 64gb Ram | 2x 1600W
$524.99

Dell PowerEdge C4130 1U AI GPU Server | 2x E6-2699 v3 | 128gb RAM | 2x 1600W
$899.99

Dell PowerEdge R530 2x E5-2630v4 H330 iDRAC8 Port Card Riser No PSU/RAM/HDD
$99.99

Dell PowerEdge FX2s + 8x FC430 Blades 16x E5-2630v4 160 Cores Rails No PSU/RAM
$699.00