ssh commands in ksh question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh commands in ksh question
# 1  
Old 02-29-2008
ssh commands in ksh question

Is there a way to shorten these commands? because this script asks for a password 3 times

scp -p /usr/local/bin/${script_name} ${servername$iy]}://usr/local/bin/
ssh ${servernames[$iy]} /usr/local/bin/${script_name}
ssh ${servernames[$iy]} rm -f /usr/local/bin/${script_name}

Basically, I'm creating a script within a script, pushing it out to a server, execute it, and then removing it.

Thanks in advance.
# 2  
Old 03-01-2008
You can get it down to two easily.
Code:
scp -p /usr/local/bin/${script_name} ${servername$iy]}://usr/local/bin/
ssh ${servernames[$iy]} /usr/local/bin/${script_name} && rm -f /usr/local/bin/${script_name}

You're obviously going into the remote node with privilege. Or /usr/local/bin is wide open which is a bad idea. I do not get the requirement for copying and deleting the script every time it is run. Is there no way to use protections to prevent it from being run? Or write it to someplace like /var/adm/.... where you can set restricted access?
# 3  
Old 03-01-2008
Another solution

Quote:
Originally Posted by pdtak
Is there a way to shorten these commands? because this script asks for a password 3 times

scp -p /usr/local/bin/${script_name} ${servername$iy]}://usr/local/bin/
ssh ${servernames[$iy]} /usr/local/bin/${script_name}
ssh ${servernames[$iy]} rm -f /usr/local/bin/${script_name}

Basically, I'm creating a script within a script, pushing it out to a server, execute it, and then removing it.

Thanks in advance.
To execute a simple script (that would execute ls -l / for example), my ideao would be to use the standard input :

echo "ls -l /" | ssh host "cat > /tmp/tmpscript && chmod +x /tmp/tmpscript && /tmp/tmpscript && rm /tmp/tmpscript"

Hope this can help...

X.
# 4  
Old 03-02-2008
This is a good candidate for an expect script. You log in once, you run your commands, you log out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

ksh with Oracle commands

works fine. echo "Deleting CHOPOne Coreaccess from LAUA..." $ORACLE_HOME/bin/sqlplus username/password@servername << ! delete from usergrpdtl where username='acker'; commit; ! but not working with "if statement" even $TMPDIR/adlogin.log exists and greater than 0. if then ... (9 Replies)
Discussion started by: lawsongeek
9 Replies

2. Shell Programming and Scripting

Sequential execution of commands in ksh

I need to run few commands in a ksh script sequentially. Some of the commands are jobs submitted to the server and the consecutive commands are dependent on the completion of the jobs submitted to the server. It works if i separate the commands into different files like this #!/bin/ksh... (1 Reply)
Discussion started by: prashob123
1 Replies

3. Shell Programming and Scripting

SED sub commands in KSH not working for me

I am using SED to edit a file (called file) the file contains the word "ERROR" and I want to use SED to: 1. Search for text "ERROR" If found, 2. Append new line with text "hoi" I tried: sed 's/ERROR/ a\hoi' file sed 's/ERROR/ a\ hoi' file I get all the time the error sed:... (7 Replies)
Discussion started by: Alex400
7 Replies

4. UNIX for Dummies Questions & Answers

Calling commands with ksh

Hi, I am not able to run below command on linux, it however works on solaris. If anyone knows the reason and a solution for it can you please let me know ? Linux ----- $> ksh 'echo hi' ksh: echo hi: No such file or directory $> which ksh /usr/bin/ksh Solaris ------ $> ksh 'echo... (2 Replies)
Discussion started by: krishnaux
2 Replies

5. Shell Programming and Scripting

Bash commands to an 'ssh' within an ssh'

I've struggled to find a solution to this problem from searching so I thought I'd write a post to see what can be done. I'm attempting to connect and run commands on 'server2' but because of security limitations I cannot access it directly. I can however ssh into 'server1' and then into... (7 Replies)
Discussion started by: mcintosh.jamie
7 Replies

6. UNIX for Advanced & Expert Users

Better KSH commands

Are there any documents available for checking the execution time taken by ksh commands? My requirement is to fine tune a set of shell scripts having lot of "echos" and "date"s. Is there a better replacement for the below code?. echo "ABC process started on `date`" some code.. echo... (12 Replies)
Discussion started by: engineer
12 Replies

7. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

8. Shell Programming and Scripting

ssh and commands

can someone point me to where it explains how to set the right commands wd ssh? cat something | while read h; do awk 'BEGIN {FS="\n"; RS=""; ORS="\n\n"} {if ($0~/'$h'/) print hdrvar,"\n",$0 }' /something/somedata ; done above works in when ssh'ing into linux machine invoke like this ssh... (10 Replies)
Discussion started by: convenientstore
10 Replies

9. UNIX for Dummies Questions & Answers

ksh substring commands

I am trying to get various portions of strings in my script, but am getting a substitution error. I followed the syntax that was described when I goggled this, but I can't get anything to work. #! /bin/ksh/ hello="adklafk;afak" #hello=${hello:3} hello=${$hello:3} happy="hey" echo... (1 Reply)
Discussion started by: anderssl
1 Replies

10. Shell Programming and Scripting

ksh GUI commands

I have a few scripts that i would like to make into GUI's. Are there scripting commands to make GUI's if so where can i get the list of commands and what they do or if anyone has an example of it. Anything will help, thanks (1 Reply)
Discussion started by: daltonkf
1 Replies
Login or Register to Ask a Question