Help with ssh ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with ssh ksh script
# 1  
Old 05-09-2013
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.

i have to clean out the sftp server folders so i do not transfer duplicate files over.

basicaly i ssh to sftp1 server
Code:
cd to directory 
rm -f *

then i do a scp of the files i need to that folder.

my question is can i stick an exit command after the rm so that i quit the ssh connection before the scp?

i am running into an issue of i think i am still on the sftp1 server while i try and do the scp which results in no files being transfered.

Code:
ssh -T ${guser}@${gsftp} <<endscript >> ${debug_log} 2>&1
echo $HOSTNAME
cd ${draw_dir}
pwd
rm -f *.*
exit
#Transfer to 
scp ${draw}* ${guser}@${gsftp}:${draw_dir} >> ${debug_log}
endscript

would this work? thanks.
i couldn't find this on the forum.

Last edited by Scott; 05-09-2013 at 02:46 PM.. Reason: Please use code tags
# 2  
Old 05-09-2013
Sure, or you could pipe the files down the stream using something like cpio or tar, continuing to use the original connection. I like 'cpio -oaH crc' and 'cpio -idmH crc' to pack and unpack, respectively. The more connections you make, the more ssh connection setup delay you eat, and the more chance the connection will fail or hit some system ssh limit. Use ssh compression, or put your choice of compression right on the pipe to speed the transfer and reduce the encrypt cost:
Code:
$ fgrep cpio mysrc/*
mysrc/bcpio:cpio -oaH crc $1 |bzip2 $2
mysrc/buncpio:bunzip2 <$2 |cpio -idmH crc $1

# 3  
Old 05-09-2013
Code:
cd ${draw_dir} || exit

is safer, because it will exit if the cd would fail - and not empty the wrong directory.
*.* matches filenames with a dot.
The endscript terminates the remote code initiated by the ssh. Shouldn't that be directly after the rm *.*, replacing the exit?
# 4  
Old 05-10-2013
The script makes no sense, as while on the remote host you scp remote host explicit to remote host implicit, so cp would do.

Last edited by DGPickett; 05-10-2013 at 01:13 PM..
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

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

3. 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

4. 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

5. Shell Programming and Scripting

KSH, coprocess and SSH

Hi there, I want to connect to a Cisco router with a KSH script via coprocess: telnet 192.168.2.82|& print -p “login” print -p "password" With telnet it works. Now I want to use SSH: ssh -T -l login 192.168.2.82|& print -p "password" The router answer me I enter a bad... (7 Replies)
Discussion started by: sylvainkalache
7 Replies

6. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

7. 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

8. Shell Programming and Scripting

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... (8 Replies)
Discussion started by: rockysfr
8 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