ssh into a shell script (KSH)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh into a shell script (KSH)
# 1  
Old 07-02-2007
ssh into a shell script (KSH)

Hi all,

Just like to ask if it is possible to do the following:

1. Have a shell script that calls ssh username@destinationhost
2. Upon successful verification, we ssh into the destination host and automatically use ksh to run a shell script that resides in the destination host. (Hopefully no further user input is required)

Thanks in advance.
# 2  
Old 07-02-2007
Hi,
The man page says,
Code:
 ssh [-l login_name] [ hostname  |   user@hostname]   [  com-mand]

Example:
Code:
ssh user@dhost "~/bin/rndm.ksh"

Thanks
Nagarajan G
# 3  
Old 07-02-2007
Before doing this there are some settings needs to be done, else you can only use interactive mode for entring password. If you need to incorporate the ssh in batch mode you have to have the keys create. See the help for ssh for more details.
# 4  
Old 07-02-2007
It's alright to have ssh in interactive mode, though I'm running into some environment trouble after ssh-ing into the shell...

Seems like I'm getting the message "TERM environment variable not set" for all instances whereby I have to execute other scripts from the main shell. Can't seem to execute commands which spawns multiple pages like "more" as the program just seems to hang there. Commands like "clear" are not working either... is it happening because UNIX can't pinpoint what TERM is?

I've tried doing set TERM=xterm, but that didn't seem to work... any ideas on what's happening?

Thanks.
# 5  
Old 07-02-2007
Alright, managed to fix the TERM environment bug...

Add the following as the 1st 3 lines of your script

#!/bin/ksh
TERM=xterm
export TERM

However, I'm still puzzled as to why the "more" command fails to work... often get an empty screen with no chance to exit the "more" command. So strange...
# 6  
Old 07-02-2007
Quick tip on SSH.

Anything residing inside quotes " " after SSH xx@xx will be executes on the server, anything not in quotes will not be executed on that server.
# 7  
Old 07-02-2007
Hmm... care to show some examples?

I'm using more in the command more "$rootdir/batchfile.log", so is this syntax correct within ssh, or must I add more quotes?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to have local shell variables in a ksh script seen on remove server in SSH block?

I have googled this and found many solutions, but none of them are working for me. I am in a korn shell, most others reference bsh, maybe that is the issue? Anyway, all I am trying to do is use a variable I have declared in my main script in a remote shell I am running through ssh. So I have a... (8 Replies)
Discussion started by: DJR
8 Replies

2. Shell Programming and Scripting

Help with ssh ksh script

Hi, I am trying to figure out a ksh script that i have and i think i found it but not sure. i am having to scp or sftp files from my remote server over 2 others to the destination. i have the rsa keys setup for the servers on my end and the username and password for the final server. ... (3 Replies)
Discussion started by: ksh_beginner
3 Replies

3. Shell Programming and Scripting

ksh script to test max number of parallel ssh connections

hello , I need to check how many parallel ssh connections my server can take the load of. I need to login to different host which i am planning to read from a file and then a write a loop which will do parallel ssh. Please provide suggestion on how i can write script for the same.\ Thank... (1 Reply)
Discussion started by: ABHIKORIA
1 Replies

4. Shell Programming and Scripting

issue on ssh command in ksh shell

Hi guru, I'm making crazy cause an issue on a ksh shell I made. In this shell I want to execute unix command on a remote machine using an ssh connection like ssh user@host 'command'..... The command is very simply, is an ls on a remote directory but it give me an unexpected result. The... (4 Replies)
Discussion started by: leobdj
4 Replies

5. Shell Programming and Scripting

ksh script with Interactive ssh on remote server

HI Unix Gurus, I an stuck in an interesting issue, where I am trying to execute a script on remote server after ssh. The script on remote server is interactive,. Whenever it is called it hangs where it expects input from terminal and I have to terminate it. I have searched through fourm... (12 Replies)
Discussion started by: Jeevanm
12 Replies

6. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

7. Shell Programming and Scripting

Help with Backup Shell Script 'ksh + awk over ssh'

Hi newbeeeee alarm i want to send a little script over ssh this script mus download a report.tar then rename and move. the report name format is report_<host.with.dot>-10-09-20-11:55:25.tar function remote_cmd_mv { _host=$1 ARCHROOTDIR='/tmp' ... (8 Replies)
Discussion started by: TigerGoods
8 Replies

8. Shell Programming and Scripting

ssh command in ksh script encounters permission error

I've created a script and copied it to another server and try to execute it at the same time but I'm getting a permission error. I'm logged on as root and I gave the file 777 permission when I created it, but I can't run it remotely via ssh command because of permission issue. Any ideas? ... (5 Replies)
Discussion started by: pdtak
5 Replies

9. UNIX for Advanced & Expert Users

Use of sudoer with ssh login shell script (KSH)

Greetings all, I'm in the midst of writing a login component for a series of shell scripts. What my login script does is this: 1. Prompt for username and read in username 2. Prompt for destination host and read in destination host 3. run ssh username and destination host 4. After user keys... (0 Replies)
Discussion started by: rockysfr
0 Replies

10. Shell Programming and Scripting

Testing ssh connection from KSH script

Hi. I have a kornshell script that runs on a daily basis as a cron job. Part of what the script does is copy the folder contents from another server to the current server (server where KSH script is running). I have a scp command, as follows: scp $REMOTE_HOST:$REMOTE_FILE_DIR/* $TMP_DIR ... (8 Replies)
Discussion started by: dmilks
8 Replies
Login or Register to Ask a Question