# Executing remotely the script

**URL:** <https://community.unix.com/t/executing-remotely-the-script/169239>\
**Category:** Shell Programming and Scripting\
**Created:** [February 20, 2007, 4:55am UTC](https://community.unix.com/t/executing-remotely-the-script/169239 "2007-02-20T04:55:46Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![elthox](https://community.unix.com/letter_avatar/elthox/32/6_449c533f586939b6e5f246632a46421f.png) [@elthox](https://community.unix.com/u/elthox)\
**Post date:** [February 20, 2007, 4:55am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/1 "2007-02-20T04:55:46Z")

</div>

Hi All,

I have a script to be executed in another machine. I connect to that machine from another server as a root ( this is the only configured access, as i cannot log in as a normal user). After that I have to switch to a normal user and that I can be able to executge that script. But all this is done manually, that why Im interested in finding a way to automate the execution and not typing always:

remsh machine\_name  
su - sc  
./script.sh

Please could anyone help me

---

<div class="post-metadata">

**Author:** ![sb008](https://community.unix.com/letter_avatar/sb008/32/6_449c533f586939b6e5f246632a46421f.png) [@sb008](https://community.unix.com/u/sb008)\
**Post date:** [February 20, 2007, 8:04am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/2 "2007-02-20T08:04:57Z")

</div>

> [@elthox](#):
>
> Hi All,
> 
> I have a script to be executed in another machine. I connect to that machine from another server as a root ( this is the only configured access, as i cannot log in as a normal user). After that I have to switch to a normal user and that I can be able to executge that script. But all this is done manually, that why Im interested in finding a way to automate the execution and not typing always:
> 
> remsh machine\_name  
> su - sc  
> ./script.sh
> 
> Please could anyone help me

```plaintext
remsh machine_name "su - sc -c \"./script.sh\""

```

---

<div class="post-metadata">

**Author:** ![elthox](https://community.unix.com/letter_avatar/elthox/32/6_449c533f586939b6e5f246632a46421f.png) [@elthox](https://community.unix.com/u/elthox)\
**Post date:** [February 20, 2007, 8:29am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/3 "2007-02-20T08:29:41Z")

</div>

Thanks for your reply  
I tried what you wrote but it didnt succeed. Here is the output

vasstat1:/tmp/vms1# remsh smsc1 "su - sc -c \"./kot\""  
ttytype: couldn't open /dev/tty for reading  
You have mail.  
stty: : Unknown error  
Not a terminal  
stty: : Unknown error  
stty: : Unknown error  
su: ./kot: not found.

---

<div class="post-metadata">

**Author:** ![sb008](https://community.unix.com/letter_avatar/sb008/32/6_449c533f586939b6e5f246632a46421f.png) [@sb008](https://community.unix.com/u/sb008)\
**Post date:** [February 20, 2007, 8:34am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/4 "2007-02-20T08:34:20Z")

</div>

> [@elthox](#):
>
> Thanks for your reply  
> I tried what you wrote but it didnt succeed. Here is the output
> 
> vasstat1:/tmp/vms1# remsh smsc1 "su - sc -c \"./kot\""  
> ttytype: couldn't open /dev/tty for reading  
> You have mail.  
> stty: : Unknown error  
> Not a terminal  
> stty: : Unknown error  
> stty: : Unknown error  
> su: ./kot: not found.

Does the script "kot" run as a cron job or does it request input?

The last error can be solved easy:  
su: ./kot: not found.

remsh smsc1 "su - sc -c \"\<full path to location of kot\>/kot\""

---

<div class="post-metadata">

**Author:** ![elthox](https://community.unix.com/letter_avatar/elthox/32/6_449c533f586939b6e5f246632a46421f.png) [@elthox](https://community.unix.com/u/elthox)\
**Post date:** [February 20, 2007, 8:45am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/5 "2007-02-20T08:45:38Z")

</div>

It is OK now, I run it successfully. Just one more question. How can I transmitt one or two parameter with the script

E.g remsh smsc1 "su - sc -c \"./kot.sh 2007-01 06845444\""

Is it correct like this?

---

<div class="post-metadata">

**Author:** ![sb008](https://community.unix.com/letter_avatar/sb008/32/6_449c533f586939b6e5f246632a46421f.png) [@sb008](https://community.unix.com/u/sb008)\
**Post date:** [February 20, 2007, 11:26am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/6 "2007-02-20T11:26:37Z")

</div>

> [@elthox](#):
>
> It is OK now, I run it successfully. Just one more question. How can I transmitt one or two parameter with the script
> 
> E.g remsh smsc1 "su - sc -c \"./kot.sh 2007-01 06845444\""
> 
> Is it correct like this?

Looks fine to me

---

<div class="post-metadata">

**Author:** ![elthox](https://community.unix.com/letter_avatar/elthox/32/6_449c533f586939b6e5f246632a46421f.png) [@elthox](https://community.unix.com/u/elthox)\
**Post date:** [February 21, 2007, 4:47am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/7 "2007-02-21T04:47:31Z")

</div>

Hi again,

The output of the script above is supposed to be returned to the calling place.  
I use rcp like below

rcp -p /var/opt/nokia/smsc/logdata/billfiles/out 172.20.1.25:/opt/output/daily\_stats/config

I cannot understand why sometimes works and sometimes no, like today. It gives me this error  
remshd: Login incorrect

Any clue?

---

<div class="post-metadata">

**Author:** ![Anubhav](https://community.unix.com/letter_avatar/anubhav/32/6_449c533f586939b6e5f246632a46421f.png) [@Anubhav](https://community.unix.com/u/Anubhav)\
**Post date:** [February 21, 2007, 5:02am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/8 "2007-02-21T05:02:29Z")

</div>

rcp is remote copy. I think you could be getting this for 2 reasons.

A. Either you have 2 different login id's on these 2 machines.

B. The password for login id you are using on the server that you are executing the script has changed.

Let me know if you need more help.

---

<div class="post-metadata">

**Author:** ![elthox](https://community.unix.com/letter_avatar/elthox/32/6_449c533f586939b6e5f246632a46421f.png) [@elthox](https://community.unix.com/u/elthox)\
**Post date:** [February 21, 2007, 5:08am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/9 "2007-02-21T05:08:55Z")

</div>

THank you for your reply

I think none of two aletrnatives is the cause of this. Because yesterday it worked and the errror occured just today. No password changed.

---

<div class="post-metadata">

**Author:** ![Anubhav](https://community.unix.com/letter_avatar/anubhav/32/6_449c533f586939b6e5f246632a46421f.png) [@Anubhav](https://community.unix.com/u/Anubhav)\
**Post date:** [February 21, 2007, 5:22am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/10 "2007-02-21T05:22:44Z")

</div>

Hmm ok one more thing to check out in that case

Verify if your .rhosts file in the remote server is configured properly i.e. to allow root access from your local host.

Check $HOME/.rhosts file

It should have permissioning as follows:

\<machine name where remsh is getting executed\> root

After checking above entries in .rhosts you can check the trust between the servers using..

#rlogin \<servername\> -l root

If you are able to logged in without prompting for password then you are done !!!

If the password is prompted then, remsh command also wont work.

Also if you have root access one thing might be that the passwords for root differ between the two machines.

Just spitting out different guesses here.

Hopefully this helps

Let me know

---

<div class="post-metadata">

**Author:** ![jambesh](https://community.unix.com/user_avatar/community.unix.com/jambesh/32/421_2.png) [@jambesh](https://community.unix.com/u/jambesh)\
**Post date:** [February 21, 2007, 5:31am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/11 "2007-02-21T05:31:43Z")

</div>

What about rsh ?? Can't i run a command/script in remote machine useing rsh ?

Examle-  
rsh REOTE\_MACHINE\_NAME -n "chmod 664 SOME\_FILE"

---

<div class="post-metadata">

**Author:** ![Anubhav](https://community.unix.com/letter_avatar/anubhav/32/6_449c533f586939b6e5f246632a46421f.png) [@Anubhav](https://community.unix.com/u/Anubhav)\
**Post date:** [February 21, 2007, 5:38am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/12 "2007-02-21T05:38:23Z")

</div>

rsh or remsh is the same thing. Regardless of what you use if your remote host file (.rhost) files are not correct you won't be able connect between two different hosts.

---

<div class="post-metadata">

**Author:** ![elthox](https://community.unix.com/letter_avatar/elthox/32/6_449c533f586939b6e5f246632a46421f.png) [@elthox](https://community.unix.com/u/elthox)\
**Post date:** [February 21, 2007, 5:42am UTC](https://community.unix.com/t/executing-remotely-the-script/169239/13 "2007-02-21T05:42:11Z")

</div>

I cannot undersand why remsh works properly and rcp (for turning back the value) doesnt work. I think the configuration for both this commands is the same, if it works for remsh should work for the other one too.
