Multiple interpreter declarations


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple interpreter declarations
# 1  
Old 11-28-2010
Multiple interpreter declarations

Hi,
I am writing a shell script that connects to a remote server and performs some tasks on the server and exits.
Since i am using a ssh connection, i am using a "expect" utility to supply the password automatically (which is present within the script).

In order to use this utility, i need to declare the executable path at the beginning of the script using interpreter declaration.
something like this: #!/usr/bin/expect

This works fine so far.
However, i am using this script as part of CGI-programming too.
The input/output of this script is available via web browser with the help of cgi-programming.

But, the real problem is , in order to achieve cgi-programming with this script, i need to have a interpreter declaration about the path of the shell.
something lik this: #!/bin/bash

Now,, the problem is , i cant have both interpreter declarations in the script.
It throws error if i try.
So, it leaves me with an option to use any one of the interpreter declarations.

is there any way or a workaround to get both the features.
What i mean is - is there any way to declare both the interpreters ( #!/usr/bin/expect and #!/bin/bash) within my shell script.

Appreciate your help.
Thanks.
# 2  
Old 11-28-2010
Have you considered using an rsa key pair and authorized_keys file?

On the machine you are logging in from, cd to the home directory of the user you will be logging into the server as. Once you are there cd to .ssh
If .ssh does not exist, create it. Run the command:
Code:
ssh-keygen -t rsa

hit enter on all three questions to accept the defaults
copy the id_rsa.pub to the server you are logging into
On the server go to the user's home directory you will be logging in as.
cd to .ssh
append the contents of the id_rsa.pub you just copied to the server to the authorized_keys file

now you should be able to log in with no password, just make sure you are running the script as the user you will be logging in as.

Last edited by ilikecows; 11-28-2010 at 06:17 AM.. Reason: added details
This User Gave Thanks to ilikecows For This Post:
# 3  
Old 11-28-2010
Thanks ilikecows for a very useful solution.
For a moment i thought this would be the best solution that you provided.
However, i can see another problem.
The problem is that this script connects to any server (specified by the user) in the network.
It means that there might be a new server coming up in the network all of a sudden and when a user runs this script, it should be able to login automatically without user intervention.

If i follow your solution, i would have to login into each and every server (that the script is goin to login ) and copy the id_rsa.pub there, which again doesn't help me as i have to give this script to the users and it wont be good to ask them to do the above tasks. Smilie
# 4  
Old 11-28-2010
You could always write a wrapper script in ksh or bash that your web server runs that calls the expect script.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Safe way to eval variable declarations?

Is there a safe way to evaluate variable declarations within a script whether they come from a .conf file, user input, or stdin? Example .conf file: server=ftp.xxxx.com port=21 user="$USER" # Hopefully allow this type of substitution domain="$DOMAIN" server="$(malicious... (4 Replies)
Discussion started by: Michael Stora
4 Replies

2. Linux

interpreter files

Can you explain me what is ment by interpreter files ?? Why and how they are used?? (1 Reply)
Discussion started by: kkalyan
1 Replies

3. Shell Programming and Scripting

Bad Interpreter

Hi. My name is Caleb (a.k.a RagingNinja) form the whited00r forums. (Whited00r makes custom firmware for iOS devices). I have been learning and creating simple shells scripts. I have been recently using VIM for Windows or using VirtualBox to run the UBUNTU OS within VirtualBox to create my shell... (2 Replies)
Discussion started by: RagingNinja
2 Replies

4. Programming

Java Interpreter

Hello guys - do you have any sample program implementing UNIX commands in an interpreter with Java? I can look up the simple ones such "ls" etc and then write my own commands. I would appreciate it. (2 Replies)
Discussion started by: cmontr
2 Replies

5. UNIX for Dummies Questions & Answers

m4 as script interpreter

#!/usr/bin/m4 when running m4 scripts with "#!/usr/bin/m4" they are executed properly, but "#!/usr/bin/m4" is printed out - how to avoid it? Thanks in advance. (5 Replies)
Discussion started by: Action
5 Replies

6. UNIX for Dummies Questions & Answers

an command interpreter

if somebody can help me pls. i need the source code for a shell which compiles C or java programs. i need a very short and simple one, just for the compiling part, in UNIX Respect (4 Replies)
Discussion started by: zlatan005
4 Replies

7. Shell Programming and Scripting

How to run a new shell with copy of current shell declarations?

How to run another shell and have all current shell dectaration copied to that new shell? I would like to have available all current declarations in a new shell. That are functions, aliases, variables. I need to test some functions that use the 'exit', but running it in current shell on... (9 Replies)
Discussion started by: alex_5161
9 Replies

8. Programming

When I am writing my own interpreter...

While trying out my hand at writing an interpreter, I was wondering about a a few issues one of which is the following: When I run a command such as jobs in the shell, I get a list of all the background jobs that are running... But if I need my interpreter to run that command, how would I be doing... (34 Replies)
Discussion started by: Legend986
34 Replies

9. Programming

Reg. Local vs Global declarations

Please go through the following two versions of code :- Version 1 --- string1 and string2 declared as Global variables The output is :-- (as expected sprintf is overwriting the first byte of string2 with NULL) string1=send string2= #include <stdio.h> char string1; char string2; main()... (2 Replies)
Discussion started by: kms
2 Replies
Login or Register to Ask a Question