read string in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read string in a file
# 1  
Old 03-12-2011
read string in a file

I'm writing a script for remote access. I wanted to put all my server's name on a file (server.txt) per line. and then the user will input the serversname and do ssh to it.

sample.
servers.txt
server1
server2
server3

user will be asked to put what server he would like to ssh with..say server1. when they input server1, they will automatically access the server remotel (ssh@server1)


# 2  
Old 03-12-2011
is this what are you looking for ?
Code:
#!/bin/sh
echo -n "enter server:-";read server
ssh `whoami`@$server

# 3  
Old 03-13-2011
thanks for the reply. i will have "servername" file on a remote server. this filename will consist of all the hostnames of my servers (say 30 servers). the script will tell a user to input the hostname, it will lookup on the servername file and if it's there, it will ssh to that server automatically. pls advise..thanks..

---------- Post updated at 06:15 PM ---------- Previous update was at 06:10 PM ----------

when it ssh, it will still actually stays on the remote machine and restart an instance on the chosen server.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

2. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

3. Shell Programming and Scripting

How to read file, and replace certain string with another string?

Hi all, the value in the following file is just an example. It could be a different value/network addresses. Here is my example of initial output in a file name net.txt Initial Output, net.txt The goal is to produce the following format which is to convert from CIDR to Netmask... (6 Replies)
Discussion started by: type8code0
6 Replies

4. Shell Programming and Scripting

How to read from file and convert from string to integer?

Hi all, I am trying to write a script to be able to Run top command Pick the PIDs that are taking more than 90% of CPU time Get more details like what is the script name and location for that PID Script should run until I manually kill it by ctrl + C I have come up with following script... (3 Replies)
Discussion started by: pat_pramod
3 Replies

5. Shell Programming and Scripting

Take input from read and place it a string in another file

Hi, This is most likely a dumb question but I could not find answer to it elsewhere. I'm building a simple menu with case /esac and want to read user's input: Please enter XYZ ; read XYZ How do I take the value of XYZ and insert it as a variable $XYZ in file file.txt ? I may need to... (9 Replies)
Discussion started by: svetoslav_sj
9 Replies

6. Shell Programming and Scripting

Read all lines after a string appears in the file.

Hi All, I want to read all lines after a perticular string {SET UP VALUES}apprears in the file. SET UP values contains direcory, number of days and file type. Step1: Read all lines below SET UP VALUES string. Step2: If set up values are not present in each record then read from default... (4 Replies)
Discussion started by: Nagaraja Akkiva
4 Replies

7. Shell Programming and Scripting

How to remove last character in a string read from file

Hello, The last character is a comma , I have tried the following: sed -e 's/\,$//' filename-to-read however - there are still commas at the end of each line...:confused: (5 Replies)
Discussion started by: learning
5 Replies

8. Shell Programming and Scripting

read string from file into variable

Hello, I need to read from a file consisting of only one integer and enter that number into variable.can anyone help? the script is written in cshell. thanks. (4 Replies)
Discussion started by: offerbukra
4 Replies

9. Shell Programming and Scripting

How to insert a string at the end of a file read

Hi, This thread is an extension of the post I posted in another folder for Unix Dummies. I am actually trying to read all the files in a folder, let say folder A. There are alot of .txt files in this folder where I have sed them and translate to numeric elements. For example:- I have... (5 Replies)
Discussion started by: ahjiefreak
5 Replies

10. Shell Programming and Scripting

Read string from a file,plz help me to check

#!/usr/bin/ksh exec 0<property while read newReceiveDir do if then sed -e 's//home/joshua/bodi/data/receive/{$newReceiveDir:25}/g/' mp_validate.sh >| mp_validate.sh elif then sed -e 's//home/joshua/bodi/data/temp/{$newReceiveDir:22}/g/' mp_validate.sh >| mp_validate.sh ... (1 Reply)
Discussion started by: joshuaduan
1 Replies
Login or Register to Ask a Question