0

I am trying to run a script remotely using ssh and the need use some parameters from remote server. Kept all parameters in remote server location temp/test/test.prm file. Getting an error saying " invoke.sh: line 20: . /temp/test/test.prm: No such file or directory "

See below for sample script. Have very basic knowledge in scripting so plz direct me

#!/bin/sh
Param1=$1
Param2=$2

ssh usr@Server1

          . ${Param1}/Client/scripts/Sample1.prm

 cd  $prmHome/$prmSetPath

 ls | sed '/\.log$/d' >  $prmHome/$prmScript/Filelist.txt

 cd $prmHome/$prmScript

 while read LINE

 do

 ExportFilName=$LINE

 ./conversion.sh $prmHome/tmp_export/convert_$Param2.csv  $prmHome/$prmSetPath/'$ExportFilName'

 done < Filelist.txt


rm -rf   $prmHome/$prmScript/Filelist.txt

exit 0



Content of  Sample1.prm
prmHome=/iis/home
prmSetPath=/export/set
PrmScript=/Client/scripts

I have tried the same trough command line after connecting to remote server using ssh and it is working, but when I am trying to do the same through a script (invoke.sh) its throwing no such file or directory error

2
  • Looks like you're trying to source your param file. But why? Is it a shell script or what? Commented Sep 17, 2015 at 13:55
  • Or just a general question, what part of your code you intend to run on remote host ? Commented Sep 17, 2015 at 14:14

2 Answers 2

1

UPDATE

This is unclear and will not work !

ssh usr@Server1
          . ${Param1}/Client/scripts/Sample1.prm

As mentioned you should use

ssh usr@Server1 ". ${Param1}/Client/scripts/Sample1.prm" 

format first.

And secondly what you expect following command to do ?

. ${Param1}/Client/scripts/Sample1.prm

Notice that there is a space in between . and the path, which is a synonym for source. So also check if the Sample1.prm have valid commands.


Looks like you are not running any ssh shell command on remote host but only on your local host.

How exactly you are running the ssh shell command ?

The code snippet in your example is poorly formatted. The general structure should look like this e.g.

  • ssh user1@server1 date

    or

  • ssh user1@server1 'df -H'

Please revise you invocation script, or make the formatting in the question appropriate.

Sign up to request clarification or add additional context in comments.

14 Comments

I need to run a script in remote server, but for which I need to pass some parameters. I am trying to invoke the same script from local server through another script. So thought in my local script first connect to remote server using ssh( I am not sure whether this is the right way, doing first time ) and then I can read a parameter file present in remote server and then use some of the parameters from the parameter file as to run remote script ).
The code in your question has nothing to do what you want to do. You should use following structure for parameters with multiple command ssh user1@server1 'df -H'
This is absolutely unreadable. Please copy the code into your question and format it !
. My intention is of ' . ${Param1}/Client/scripts/Sample1.prm ' this command is to execute this file so that I can use the parameters mentioned in Sample1.prm file. and all the code after this line ( my expectation is ) should execute on remote server
If you intend to run the other lines too then the best will be to create a script with the content which you want to run on each remote host. Copy the script to each remote host and then execute it via ssh shell command.
|
0

Update:

If you want to execute your code on remote server via ssh, you can do following:

  1. Create separate file my_script.sh for your code you want to run remotely, and paste following code:

     #!/bin/bash
     function my_function() {
        prmHome=$1
        prmSetPath=$2
        PrmScript=$3
    
        cd  $prmHome/$prmSetPath
    
         ls | sed '/\.log$/d' >  $prmHome/$prmScript/Filelist.txt
    
         cd $prmHome/$prmScript
    
         while read LINE
    
         do
    
         ExportFilName=$LINE
    
         ./conversion.sh $prmHome/tmp_export/convert_$Param2.csv  $prmHome/$prmSetPath/'$ExportFilName'
    
         done < Filelist.txt  
         rm -rf   $prmHome/$prmScript/Filelist.txt  
    
        exit 0 
      }
    
  2. Then you can call you function remotely, by sourcing your file on remote server:

    ssh usr@Server1 '. my_script.sh; my_function "/iis/home" "/export/set" "/Client/scripts"'

That's it :)


This code will not work:

ssh usr@Server1

          . ${Param1}/Client/scripts/Sample1.prm

Change it like that:

ssh usr@Server1 ". ${Param1}/Client/scripts/Sample1.prm"

6 Comments

Thanks, but I want execute all the code which mentioned after this line on remote server( server1) only. how can I do that?
@Sham hmm, ok but why not put all your code in separate file and then call it via ssh, like that: ssh $my_server ". /<somepath>/myscpritp.sh; my_function $param1 $param2" ?
can you explain little more. put all code means( all code which I need to run on remote server ?) what do you mean by my_function . Since I posted the code the original post can you make out of it. Sorry not much idea on ssh all
Thanks Samuel. Let me try and will let you know
I think the call function syntax is incorrect. not executing
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.