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.
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:
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
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.
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)
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)
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)
#!/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)
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)
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)
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)
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)