-
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

Netac 2TB 1TB 512GB 256GB Internal SSD 2.5inch SATAIII Solid State Drive lot
$379.00

Samsung 2.5" 870 EVO SSD SATA III 250GB 500GB 1TB Internet Solid State Drive Lot
$60.00

Micron MTFDDAK256TBN 256 GB, Internal ,2.5" SSD
$23.00

Samsung New SSD 970 EVO Plus 2TB 1TB 500GB 250GB NVMe M2 Internal Hard Drive Lot
$79.99

Crucial MX500 1TB 2.5" SATA III Internal SSD CT1000MX500SSD1
$99.99

Crucial MX500 250GB 2.5" SATA III SSD - Preowned
$29.00

Samsung 256 GB Internal SATA SSD Fully Tested 50%-79% Health
$24.00

2 PACK 128 GB SSD M.2 2280 SATA Solid State Drive Major Brands, Samsung, LiteON
$28.00

Netac 120GB 256GB 1TB 2TB Internal SSD 2.5'' SATAIII 6Gb/s Solid State Drive lot
$119.99

Netac 256GB SSD 2.5'' SATA III 6Gb/s Internal Solid State Drive 500MB/s PC/Latop
$40.00