Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: ssh problem

  1. #1
    Join Date
    Apr 2007
    Beans
    Hidden!
    Distro
    Ubuntu 7.04 Feisty Fawn

    Cool ssh problem

    This problem is driving me insane. I have been breaking my head for a couple of hours and can't figure it out.

    I am trying to run a script on a server remotely with ssh using the below command with no success

    ssh user@server.edu sh foldername/myscript.sh

    and the script is:
    >>>>>>>>>>>>>>>>
    unset DISPLAY
    matlab > matlab.out 2>&1 << EOF
    matlabfile
    print file
    exit
    EOF
    >>>>>>>>>>>>>>>>
    here I am making matlab run a matlab script called "matlabfile"
    But the script somehow does not run.

    I know for a fact that the way I am calling the script through ssh is right and I am pointing in the right location of the script. However the fact that is in a folder which is not my main user directory causes it to not be able to run through ssh. I can run it fine through ssh if the script is in the main user directory but not if it is in a folder within the main directory.

    I can also confirm that if I connect to the server and cd into the folder and run it from there (sh myscript.sh), it also runs just fine.

    This is driving me crazy.

    Can anyone help?
    Thanks!

  2. #2
    Join Date
    Feb 2007
    Beans
    2,729

    Re: ssh problem

    You'll get better results to your questions if you post in forums more appropriate to your questions (eg. networking instead of Education and Science).

    First, what exactly is the error message / error code ?

    When you run you script over ssh, the shell's working directory will be "user"'s home directory. I presume foldername is the same as /home/user/foldername (or equivalent). So you are telling the remote shell to run the command myscript.sh by a relative pathname (foldername/myscript.sh). However, your script is assuming that the file matlabfile is either in user's home directory, or that matlab knows where to find it by name.

    What directory is your matlabfile located in?

    Add the code to the beginning of your script:

    Code:
    echo $PATH
    pwd
    ls -l matlabfile
    This should make things a little more clear.

    Finally, save yourself a little typing. Add

    Code:
    #!/bin/sh
    as the first line of your script and then:

    Code:
    chmod a+x foldername/myscript.sh
    Then you can just type foldername/myscript without "sh" preceeding, as well as:

    Code:
    ssh user@server.edu foldername/myscript.sh
    MrC

  3. #3
    Join Date
    Jun 2007
    Location
    Tacoma, WA
    Beans
    244
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: ssh problem

    I'm a bit confused about which dir's you have access to. In your example, do you have write permission to $HOME/foldername on user@server.edu? If not, is it possible to copy the script to a directory that will allow you to write the matlab.out file?

  4. #4
    Join Date
    Apr 2007
    Beans
    Hidden!
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: ssh problem

    Quote Originally Posted by Mr. C. View Post
    First, what exactly is the error message / error code ?
    It doesn't actually return any errors it just doesn't seem to run because there are output files that I am expecting and they do not turn up.

    Quote Originally Posted by Mr. C. View Post
    What directory is your matlabfile located in?
    my matlabfile is in the same directory as the myscript.sh in user/foldername


    P.S. Sorry I posted it here because I thought Networking was more about support for Ubuntu itself.

  5. #5
    Join Date
    Apr 2007
    Beans
    Hidden!
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: ssh problem

    Quote Originally Posted by meatpan View Post
    I'm a bit confused about which dir's you have access to. In your example, do you have write permission to $HOME/foldername on user@server.edu? If not, is it possible to copy the script to a directory that will allow you to write the matlab.out file?
    I have access to:
    /home/user
    (and any folders within obviously)

    the script I need to run (myscript.sh) is under:
    /home/user/foldername

    I have an ssh public key under:
    /home/user/.ssh


    Sorry about the confusion.
    Last edited by elfstone214; June 7th, 2007 at 06:49 AM.

  6. #6
    Join Date
    Feb 2007
    Beans
    2,729

    Re: ssh problem

    Ok, then, there's your problem.

    Your script is started with its working directory as your home directory. Your script's does not indicate where matlab should find the "matlabfile" file. Matlab is started up with its working directory as your home directory also. How can it possibly know to look inside foldername to find matlabfile ?

    Replace matlabfile with $HOME/foldername/matlabfile

    Always use absolute paths, or know how to control your relative paths, when creating scripts.

    MrC

  7. #7
    Join Date
    Apr 2007
    Beans
    Hidden!
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: ssh problem

    Code:
    echo $PATH
    pwd
    ls -l matlabfile
    I tried adding this but it didn't work

    I appears for some reason it tries to run the script from:
    /home/user

    when I added that snip of code it pwd returns
    /home/user

    when it should be
    /home/user/foldername

    and ls -l matlabfile returned an error because the matlabfile is also not under
    /home/user

  8. #8
    Join Date
    Apr 2007
    Beans
    Hidden!
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: ssh problem

    Quote Originally Posted by Mr. C. View Post
    Ok, then, there's your problem.

    Your script is started with its working directory as your home directory. Your script's does not indicate where matlab should find the "matlabfile" file. Matlab is started up with its working directory as your home directory also. How can it possibly know to look inside foldername to find matlabfile ?

    Replace matlabfile with $HOME/foldername/matlabfile

    Always use absolute paths, or know how to control your relative paths, when creating scripts.

    MrC

    Alright, I'm going to give that a try.

  9. #9
    Join Date
    Feb 2007
    Beans
    2,729

    Re: ssh problem

    Of course it doesn't work. The ls command should not return /home/user/foldername. You are misunderstanding working directories and process invocation.

    Invoking a program as either:

    Code:
      program
    or
    Code:
       directory/program
    does not change the working directory. When the program starts, its working directory is exactly the same as the working directory of the process that exec'd it. In this case, its a shell, started by the ssh server. And when you run foldername/myscript.sh, the working directory is not changed; rather, the shell just attempts to exec some file named foldername/myscript.sh

    Use full pathnames if you don't understand the working directory concept. If you want to learn more about this, read the section of PATH in Lecture 5 under Coursework at http://cis68a.mikecappella.com/ .

    MrC

  10. #10
    Join Date
    Apr 2007
    Beans
    Hidden!
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: ssh problem

    Got it!

    many thanks guys! really appreciate your help.

    I dunno what I would do without these forums

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •