The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
what is wrong with this tr -d? cleansing_flame UNIX for Dummies Questions & Answers 3 02-06-2008 12:34 PM
What’s wrong with the following? vrn UNIX for Dummies Questions & Answers 8 03-19-2006 09:09 PM
where have i gone wrong? Blip Shell Programming and Scripting 3 01-28-2004 04:43 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-25-2006
jzocco jzocco is offline
Registered User
  
 

Join Date: May 2006
Posts: 1
Bash Secure Shell Script

im trying to create a little script that does a secure shell login based on some input(ip address, server name, etc...)
everything in perenthesis() as been edited for privacy reasons

I cant figure out what im doing wrong? if you can post some info for me that would be awsome

------------------------The Script------------------------------
#!/bin/bash
port="22"

echo 'What server:?(server1, server2 or type ip address)'
read $server

if [ $server = "(server1)" ];
then
ssh (uname)@(ipaddress) -p(port number)
elif [ $server = "(server2)" ];
then
ssh (uname)@(ipaddress)
elif [ "$server" -eq *.*.*.* ];
then
echo 'User:?'
read $user
echo 'port:?'
ssh $user@$server -p$port
else
exit
fi

Last edited by jzocco; 05-25-2006 at 03:23 PM..
  #2 (permalink)  
Old 05-25-2006
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
I don't understand - do you have a problem with the script above? Either way, it looks like you're being a bit redundant - instead of them typing in the server name, then you check if they typed in the server name, then you execute ssh with the server name, why not accept their input:
Code:
#! /bin/bash
echo -n "Enter a server name or IP address: "; read _srv
echo -n "Enter username for $_srv, or enter for \"${LOGNAME}\": "; read _usr
[[ -n $_usr ]] && _usr=${_usr}@
echo ssh ${_usr}${_srv} || {
 echo "SSH encountered an error! " >&2
 exit 1
 }
However, you may need to insert some error handling, validation, etc...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0