Execute command from terminal on remote machine


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute command from terminal on remote machine
# 1  
Old 10-09-2007
Execute command from terminal on remote machine

Hi All,

I want to execute some commands on unix machine from the mac machne. I have two options for doing so, I am confused which is the best way of doing. Here are two options.

Requirement:
Execute command on the remote server machine. Commands to be executed itself contain arguments to be passed to some script.

Option1:
1. Perl script to do ssh and expect to connect to the remote machine and execute command over there.
Complexity/Overhead: If I need to execute any new command, I have to overwrite '.exp' file.

2. Use Net::SSH:Expect perl module to do so.
Complexity/Overhead: Bit difficult to install perl module on mac os. Smilie

I am confused here which is the best option which suite my requirement.

Will appreciate any guidance.

Thanks,
Ranu
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

How can I execute local script on remote machine and include arguments?

I have a script in local server cd /home/dell/work/BOP/testdir ./processchk po (here processchk is a script & po is passed as an argument) Now I want to execute this script from remote server ssh $username@$hostname "cd /home/dell/work/BOP/testdir; ./processchk po" But Its getting error... (9 Replies)
Discussion started by: manohar2013
9 Replies

3. Shell Programming and Scripting

Execute shell script on remote machine

I want to execute a shell script(set of commands) on remote machine and that script takes input from text file(local machine). Please refer below: ssh user@hostname 'bash -s'< ./test.sh file.txt But i got the error file.txt doesn't exist. Can anyone help me on this. Content of test.sh: ... (2 Replies)
Discussion started by: manishtri88
2 Replies

4. UNIX for Dummies Questions & Answers

Execute shell script in remote machine

Hi All, We have 2 servers A and B. B is having a sctipt called b.sh in path /home/dev/scripts. Now my requirement is i want to execute b.sh from server A. Kindly help me. (3 Replies)
Discussion started by: Girish19
3 Replies

5. IP Networking

Execute script located on a remote machine

So, is there way of automating this ? My ultimate goal is to run some cmd script in windows and it should connect to a remote unix host and run a script x.sh located on the remote unix host. I was wanting to achieve this by using WinSCP and Putty only. If possible let me know how and if not... (25 Replies)
Discussion started by: mohtashims
25 Replies

6. Shell Programming and Scripting

Change user on remote machine and execute script!

Hi, I need to login into remote server and execute a shell script over there. As of now i am making use of ssh command ssh primUser@135.254.242.2 sh /poll.sh I am logging in as primUser but unless i change the user to root the script execution on the remote machine is not possible. ... (5 Replies)
Discussion started by: goutham4u
5 Replies

7. SCO

Execute command in remote

Hi, How to execute unix commands in remote unix servers? Thanks, Pintu (2 Replies)
Discussion started by: pintupatro
2 Replies

8. Shell Programming and Scripting

how to execute a script on remote machine

hi unix guru's i am new to unix shell programming. i found a trouble in executing a script(bali.ksh) which is available on serverA with username xyza, this script contains sqlplus command to retrive the data from the database available on other serverC. Now i need to run the above script... (4 Replies)
Discussion started by: balireddy_77
4 Replies

9. UNIX for Dummies Questions & Answers

execute a command in remote

how exec a command (ex. a cut or grep ) in anoter pc i have IP address, login and password. (another account of unix system) what's the sintax of command ??? es. my ip is 192.xx.xx.xx i make a exec of "ls" redirect in outpu file (> "file) in another pc ( ip 192.44.55.2xxx) (3 Replies)
Discussion started by: ZINGARO
3 Replies

10. UNIX for Dummies Questions & Answers

Plz Help : How to use write command to execute command on some other terminal

Hi Group , I m trying to execute commands on some other system using write command but inspite of executing the commands they r passed as simple messages. - i m writing >write user-id ! ls o ctrl-d inspite of executing the command ls,other terminal shows ! ls. Thnx in advance. (2 Replies)
Discussion started by: Aashish
2 Replies
Login or Register to Ask a Question
SSH2_EXEC(3)								 1							      SSH2_EXEC(3)

ssh2_exec - Execute a command on a remote server

SYNOPSIS
resource ssh2_exec (resource $session, string $command, [string $pty], [array $env], [int $width = 80], [int $height = 25], [int $width_height_type = SSH2_TERM_UNIT_CHARS]) DESCRIPTION
Execute a command at the remote end and allocate a channel for it. PARAMETERS
o $session - An SSH connection link identifier, obtained from a call to ssh2_connect(3). o $command - o $pty - o $env -$env may be passed as an associative array of name/value pairs to set in the target environment. o $width - Width of the virtual terminal. o $height - Height of the virtual terminal. o $width_height_type -$width_height_type should be one of SSH2_TERM_UNIT_CHARS or SSH2_TERM_UNIT_PIXELS. RETURN VALUES
Returns a stream on success or FALSE on failure. EXAMPLES
Example #1 Executing a command <?php $connection = ssh2_connect('shell.example.com', 22); ssh2_auth_password($connection, 'username', 'password'); $stream = ssh2_exec($connection, '/usr/local/bin/php -i'); ?> SEE ALSO
ssh2_connect(3), ssh2_shell(3), ssh2_tunnel(3). PHP Documentation Group SSH2_EXEC(3)