Find the answer to your Linux question:
Results 1 to 7 of 7
Hi, I am having a script that needs to be executed on set of servers from a host server. It has parameters to get input from the remote machine where ...
  1. #1
    Just Joined!
    Join Date
    Jan 2012
    Posts
    5

    Shell remote file execution issue

    Hi,

    I am having a script that needs to be executed on set of servers from a host server.
    It has parameters to get input from the remote machine where it has been executed.
    But the script needs to be in the host server without transferring it to remote servers.

    Any ideas.....

    Example :

    echo " enter a sample value "
    read n
    echo " the entered value is $n"
    touch /tmp/$n
    ls /tmp

    I tried executing the script on remote server, but failed to read the input from remote server.

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,097
    Does it need to be interactive input on the remote machine?
    ie: Someone actively enters something?

    Or is it rather data, that is available/can be generated on each remote machine in an automated way?


    Intreractive would be quite tricky...
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Jan 2012
    Posts
    5
    !#/bin/bash
    echo " enter a sample value "
    read n
    echo " the entered value is $n"
    touch /tmp/$n
    ls /tmp
    echo " the file named $n is created under /tmp"

    after that i'm trying to execute from host server using the following command

    ssh root@server1 'bash -s' < filename

    Here the script needs interactive input from the remote machine.
    Above is the procedure i tried to run,but failed while reading the input.

  4. #4
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,097
    So you really need interactive input.
    Sorry, I believe there is no quick way to solve this.
    - You would need to deal with timeouts,
    - multiple users (if you dont want to hardcode it to root (which would be bad for the hardcoding and using root))
    - and even if you know the user, you do not know his/her session.
    You must always face the curtain with a bow.

  5. #5
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    Quote Originally Posted by ggigk View Post
    !#/bin/bash
    echo " enter a sample value "
    read n
    echo " the entered value is $n"
    touch /tmp/$n
    ls /tmp
    echo " the file named $n is created under /tmp"

    after that i'm trying to execute from host server using the following command

    ssh root@server1 'bash -s' < filename

    Here the script needs interactive input from the remote machine.
    Above is the procedure i tried to run,but failed while reading the input.
    The way I read that code, the only action the script is executing that must be done on the remote system is the creation of the file in /tmp. Is there any reason why you can't get the user input locally, then ssh to the remote machine and do the touching? e.g.:

    Code:
    !#/bin/bash
    echo " enter a sample value "
    read n
    echo " the entered value is $n"
    ssh root@server1 "touch /tmp/$n;ls /tmp"
    echo " the file named $n is created on server1 under /tmp"
    basically, you execute any "script" remotely without copying it, by just stringing your commands together with semicolons (provided that your commands are shell built-ins or programs that otherwise exist on the other system).

  6. #6
    Just Joined!
    Join Date
    Jan 2012
    Posts
    5
    The script given above will not give the current status whether the file already exists there or not but it will directly create the file but how can we make realtime check and creation of file inside remote server. any ideas please share.

  7. #7
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    Code:
    file=/tmp/$n
    ssh root@server1 "if [ -f $file ]; then echo file $file exists; else touch $file;ls $file;fi"

Posting Permissions

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