issue on ssh command in ksh shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting issue on ssh command in ksh shell
# 1  
Old 09-17-2012
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 command is built using a variable:
ssh user@host 'ls ${var}' where var is a concatenation of others variables. Whith this command I want to retrieve a specific file with a specific format like 20120917_filename.csv.gz
So the first variable contain the path in which I looking for the file, the second contains the date and the third contain the extension (.csv.gz).
Because the filename varying I must use the * in the concatenation.
The variable var=${varpath}${vardate}_*${varext}
varpath=/oracle/admin/files/
vardate='date "+%Y%m%d"'
varext=.cvs.gz
The issue is related the variable because if I write:
ssh user@host 'ls ${var}'
it return all the file in the dir even if it executes only the ls, meanwhile if I write
ssh user@host 'ls /oracle/admin/files/'date "+%Y%m%d"'_*.csv.gz'
it works correctly.
I don't know why it gave me different result, peraphs is the * that cause the unexpected result but I spend all the day looking for a solution but without result.
Please give me your opinion and contact me if you needed more explanation.
Thanks a lot to all.
# 2  
Old 09-17-2012
Code:
 
var="${varpath}${vardate}_*${varext}"

ssh user@host 'ls "$var"'

# 3  
Old 09-18-2012
Code:
ssh user@host 'ls "$var"'

Hi, it seems didn't work.

Then ls command is executed correctly only if the path or the filename is hard coding in shell.
If I use variables the result is wrong.

Smilie
# 4  
Old 09-18-2012
Quote:
Originally Posted by leobdj
Code:
ssh user@host 'ls "$var"'

Hi, it seems didn't work.

Then ls command is executed correctly only if the path or the filename is hard coding in shell.
If I use variables the result is wrong.

Smilie
I did not red the whole thing, just a quick tip :

Code:
 ssh user@host "ls $var"

The way you wrote the code I don;t think the substitution of $var can be done
# 5  
Old 09-18-2012
Yeeeeesss!!!!!!!!!!

Perfect now it works.
Great, now I can test my shell!

Thanks, thanks, thanks to all for the support.
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

Shell script for ssh command listening

Hi, I'm trying to write a shell script checks if there is ssh command listening on port 1080 at loop back interface. If there is, just exit nicely with exit code 0. If not, start command: #ssh -D 1080 smsuser@10.76.172.23 ping -i 60 localhost The ssh keys needs to be generated and... (2 Replies)
Discussion started by: Kijana_kenn
2 Replies

3. Shell Programming and Scripting

Shell Script with ssh command

How do I use the ssh command to connect to another server without the password prompt? I use: ssh user@host and it prompts for the password. how do I include the password in the ssh command? alternatively, how do you execute 1 command from server A on server B? thanks, ... (4 Replies)
Discussion started by: toughlittleone
4 Replies

4. Shell Programming and Scripting

Shell script with wget in ssh command

Hi, I am using a linux with bash. I have a script written which will login to a remote server and from there it runs a "wget" to downlaod a build file from a webserver. Here is the line inside the script: ssh -t -q -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@${a}'wget... (4 Replies)
Discussion started by: sunrexstar
4 Replies

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

6. Shell Programming and Scripting

Help with ssh command in shell script

Hi All, I am using ssh in my shell script. Can any one please suggest me option so that i can avoid the login message as below in the execution: NOTE: Please note that you have logged into the newer version of server "gabbro" ******* Performing functions to this computer withe the... (6 Replies)
Discussion started by: vikash_k
6 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. UNIX for Advanced & Expert Users

find command from shell scipt (ksh) problem

Hi experts, I have a simple shell script as follows. #!/bin/ksh FIND_STRING="\( -name 'testfile*.Z' -o -name 'DUMMY_*' \) " find /tmp -type f $FIND_STRING -print When I run this with ksh -x testscript, I get the following output. + FIND_STRING=\( -name 'testfile*.Z' -o -name... (6 Replies)
Discussion started by: kodermanna
6 Replies

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

10. 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
Login or Register to Ask a Question