Register
It is currently Mon Sep 01, 2014 5:26 pm

User Interaction Script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Tue Apr 28, 2009 4:03 am   

Joined: Sun Apr 26, 2009 10:11 am
Posts: 5
Hi All,

I'm new to scripting and is currently encountering problems with my script. I'm trying to create a script that would ssh to a certain "server" and perform basic system checks. The IP Address of the server is given by the user (User Interaction) in the following format -> /home/group/user/scripts/server/system/connection

This script works because i manually assigned the IP Address. But how would i do this so that the script would automatically cat a file and grep the server IP based on the user's input? Any hints/suggestions would really be appreciated.

Code:
#!/bin/bash
clear
echo " Enter Directory Path "
read server_path
ssh noc@[b]10.9.12.73[/b] tail $server_path/data.log




Thanks in advance.


Top
 Profile  
 PostPosted: Tue Apr 28, 2009 1:09 pm   

Joined: Sun Apr 26, 2009 10:11 am
Posts: 5
Found a way (dunno if its the easiest way but it worked anyway) to separate the directory path using the cut command. Unfortunately encountered another problem.

Here's what i did. Assuming that i have saved the "server_path" to a file (server_path.txt)

bash-3.00$ cat server_path.txt | cut -c26-31
server

Now i need to find a way to redirect the output or value of variable to a file (server_path.txt) so i can use cut. Any suggestions/ideas?

#!/bin/bash
clear
echo " Enter Server Path "
read $server_path


Thanks in advance.


Top
 Profile  
 PostPosted: Tue Apr 28, 2009 11:28 pm   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
redirection is easy.

Code:
my_variable="This is my variables content"
echo $my_variable >> file.txt


the redirection quote >> tells the shell to append this output onto the file file.txt.
If you want to replace the file when doing this use just > instead :)

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Wed Apr 29, 2009 12:29 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
If your IP_file contains only one IP per line, and there are not too much,
then:
Code:
#!/bin/bash
clear
echo " Enter Directory Path "
read server_path
# read the IP_file, each line preceded by a number
cat -n IP_file
# ask for entering the line number with the IP ou want to ssh to
read -p "Please, enter the line number: " IP2ssh
# ssh to IP retrieved by sed
ssh noc@$(sed -n "${IP2ssh}p" IP_file) tail $server_path/data.log


If your IP_file has another format, please provide a sample of it.


Top
 Profile  
 PostPosted: Wed Apr 29, 2009 5:23 am   

Joined: Sun Apr 26, 2009 10:11 am
Posts: 5
I was able to get it to work. I didn't see the dollar sign on the read command that's why i was having a hard time redirecting the output to a file :D

Quote:
#!/bin/bash
clear
echo " Enter Server Path "
read $server_path


Thanks all for your help :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP