Operating System - HP-UX
1834346 Members
1828 Online
110066 Solutions
New Discussion

run bat file after ssh to windows

 
tom quach_1
Super Advisor

run bat file after ssh to windows

Hello,
please help on some syntax on windows.

the script that using SSH to connect from UNIX to windows and run a bat file from windows.
the connection was fine. only problem was, it ran everything in the home dir "c:\AAA" the home that i defined in ssh on windows side.
#.testconn.sh
#!/bin/sh
sleep 2;
ssh -T IS-TOMQ-XP<test.bat
EOF
on windows the home dir is C:\AAA
test.bat
rename tom.test tom.log (this one was working fine as long as all the files were in c:\AAA
my question:
how can i put the bat file outside the home_dir and still be able to call it from unix script.
and please correct the syntax for test.bat

test.bat
cp C:\test\sys.log c:\tom\sys.log


Thanks in advance.
Tom



9 REPLIES 9
Peter Nikitka
Honored Contributor

Re: run bat file after ssh to windows

Hi,

you can simply append the remote command to the ssh command as a parameter, e.g.:
ssh remuser@otherhost 'remcmd1 remarg1'

If the access rights are permit it, you can use something like
ssh winuser@winpc 'C:\data\remcmd1 d:\mydir\remarg1'

mfG Peter

PS: perhaps you'll have to double the backslashes: C:\\...
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
SANTOSH S. MHASKAR
Trusted Contributor

Re: run bat file after ssh to windows

Hi,

U can keep ur test.bat anywhere and use
full path of for test.bat while connecting to ssh.

eg.

if u keep test.bat in D:\ABC\123
then use following to connect

ssh -T IS-TOMQ-XP 'D:\ABC\123\test.bat'


-Santosh
Matti_Kurkela
Honored Contributor

Re: run bat file after ssh to windows

> how can i put the bat file outside the home_dir and still be able to call it from unix script.

Use a full path name. If the test.bat is located in X:\BBB\CCC, start it with
"X:\BBB\CCC\test.bat" instead of just "test.bat".

Alternatively, place a command "cd X:\BBB\CCC" just before starting the test.bat.

Of course, the file permissions must be set so that you are allowed to execute the test.bat file in its new location.

Syntax correction for test.bat: the command to copy files is "cp" in Unix, but in Windows it's "copy". There is also "xcopy" if you need extended functionality.
MK
tom quach_1
Super Advisor

Re: run bat file after ssh to windows

Thank you!

test.bat
cp tom.tom c:\\a

this bat file does not work, please correct

Thanks,
Tom
tom quach_1
Super Advisor

Re: run bat file after ssh to windows

Thank you,

but none of these were working even permission of these folder on windows are RWX

these command lines below just hung.

$ssh -T IS-TOMQ-XP 'c:\aa\test.bat'
Killed by signal 2.
sunuxdev:[tquach]:/home/tquach
$ssh -T IS-TOMQ-XP 'C:\aa\test.bat'
Killed by signal 2.
sunuxdev:[tquach]:/home/tquach
$ssh -T IS-TOMQ-XP "C:\aa\test.bat"
Killed by signal 2.
sunuxdev:[tquach]:/home/tquach
$ssh -T IS-TOMQ-XP "cd C:\aa\test.bat"
Killed by signal 2.
sunuxdev:[tquach]:/home/tquach

thanks,
TOm
Yogeeraj_1
Honored Contributor

Re: run bat file after ssh to windows

hi,

on windows environment, "cp" does not exist. please user "copy" instead.

E:\Documents and Settings\yogeeraj>copy /?
Copies one or more files to another location.

COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/A | /B ] source [/A | /B]
[+ source [/A | /B] [+ ...]] [destination [/A | /B]]

source Specifies the file or files to be copied.
/A Indicates an ASCII text file.
/B Indicates a binary file.
/D Allow the destination file to be created decrypted
destination Specifies the directory and/or filename for the new file(s).
/V Verifies that new files are written correctly.
/N Uses short filename, if available, when copying a file with a
non-8dot3 name.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line. Default is
to prompt on overwrites unless COPY command is being executed from
within a batch script.

To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format).

E:\Documents and Settings\yogeeraj>

hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
tom quach_1
Super Advisor

Re: run bat file after ssh to windows

Thank you for your helps.

i meant "copy" not "cp" thanks for point that one out.

when i run this script from UNIX, after it connects to windows, the test.bat is windows command ?
#!/bin/sh
sleep 2;
ssh -T IS-TOMQ-XP <'c:\aa\test.bat'
EOF

Thanks,
Tom
Peter Nikitka
Honored Contributor

Re: run bat file after ssh to windows

Yes, Tom!

The command 'cmd' in
ssh remhost cmd
is executed at the remote host and therefore has to be written in a syntax 'remhost' understands!

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
tom quach_1
Super Advisor

Re: run bat file after ssh to windows

Thank you all for your supports.
i still could not call the script from anywhere else then the home that i had defined on windows, but i think i can live with that.
Thank you,
Tom