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 ...
- 01-31-2012 #1Just 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.
- 01-31-2012 #2
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.
- 02-01-2012 #3Just 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.
- 02-01-2012 #4
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.
- 02-02-2012 #5Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
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.:
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).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"
- 02-03-2012 #6Just 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.
- 02-03-2012 #7Linux 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"


Reply With Quote
