I am trying to create BAT file to run WS_FTP PRO wsftppro.exe command line using Connection Configuration. I save Connection Configuration is working in the UI, however, when trying to call it in windows command prompt it fails.
"c:\Program Files (x86)\Ipswitch\WS_FTP 12\wsftppro.exe" -s "local:c:\FTP\CLIENT\CLIENTS.C0000" -d "CJ PRODUCTION UPLOAD:INTAKE.UP.CLIENTS.C0000"
Error log: Use MVS Dsname conventions
I have also tried using single quotes:
"c:\Program Files (x86)\Ipswitch\WS_FTP 12\wsftppro.exe" -s "local:c:\FTP\CLIENT\CLIENTS.C0000" -d "CJ PRODUCTION UPLOAD:'INTAKE.UP.CLIENTS.C0000'"
Error log: Remote path not found
How can create a BAT file to run WS_FTP PRO wsftppro.exe command line using Connection Configuration?
The single quote is required for the remote dir path to be valid.
The single quote is only used once, no closing single quote.
-s "local:c:\FTP\CLIENT\CLIENTS.C0000" -d "CJ PRODUCTION UPLOAD:'INTAKE.UP.CSSCE.CLIENTS.C0000"
Powershell code to run it:
$args = #"
-s "local:c:\FTP\CLIENT\CLIENTS.C0000" -d "CJ PRODUCTION UPLOAD:'INTAKE.UP.CSSCE.CLIENTS.C0000"
"#
Start-Process "c:\Program Files (x86)\Ipswitch\WS_FTP 12\wsftppro.exe" $args
Related
I am trying to run a shell script located on a Linux server from Windows. The shell script does two things:
Do a sed command to replace text in an .sql file in the same directory.
Run the .sql file with sqlplus.
The shell script:
!/bin/sh
arg1=$1
arg2=$2
arg3=$(echo $arg1 | tr '[:lower:]' '[:upper:]')
arg4=$(echo $arg2 | tr '[:lower:]' '[:upper:]')
echo $arg1
echo $arg2
echo $arg3
echo $arg4
sed -i "s/$arg3/$arg4/g" sequence.$arg1.sql
sqlplus $arg2/$arg2#MYDB <<EOF
#sequence.$arg1.sql
exit;
(My database is located on the same Linux server.)
1) Script runs correctly when I log in to the server via MobaXterm
Connect to server with userID.
Set my_env.
cd to the shell script's directory.
Run script with ./myscript.sh with arguments.
2) Same shell script runs successfully via .cmd manually
Create a Windows script test.cmd on my Windows PC.
In the .cmd file I have the line:
plink.exe -ssh userID#Server
After the console window pops up, I repeat the steps 2 to 4 and script runs successfully.
What I am failing to do so is to automate the whole process.
Here's the line in my .cmd file which I attempted:
plink.exe -ssh userID#Server /myfilepath/myscript.sh %arg1% %arg2%
I can see the arguments passed correctly using multiple echo in the shell script. However, the shell script fails to locate the .sql file.
Error log:
/mypath/myscript.sh[1]: !/bin/sh^M not found [No such file or directory]
myarg1value
myarg2value
:No such file or directory[myarg1value]
/mypath/myscript.sh[12]: sqlplus: not found [No such file or directory]
I also tried below, but unfortunately with same result:
plink.exe -ssh userID#Server -m command.txt
Where file command.txt contains:
. my_env
cd /filepath/
./myscript.sh %arg_with_actual_value%
I do not know why it is not working, especially when 2) works and the script is relatively simple.
Do I assume things incorrectly about plink (path, variable, etc.)?
Is Cygwin the only way out?
I tried not to rely on yet another tool as I have been using plink.
EDIT: While the line
sed -i "s/$arg3/$arg4/g" sequence.$arg1.sql
fails to run on the .sh, i can run it on the .cmd file itself via:
plink.exe -ssh userID#Server sed -i "s/%arg3%/%arg4%/g" /myfilepath/sequence.%arg1%.sql
Hence I am suspecting the problem comes from the .sh file not having the required components to run (i.e. set env variable, path, etc)
This is not a solution but partially fixed some issue, thanks to Martin Prikryl and Mofi's input:
in the command.txt, the following needs to be set:
ORACLE_SID
ORACLE_HOME
PATH
after these are set, the sqlplus and sed will work normally. However, passing values from .cmd through plink to Linux's shell script seems to have issue with the actual value being passed. The variable will have the assigned value along with some unreadable characters. In this case,
sqlplus $arg2/$arg2#MYDB
login fails because arg2 contains some other char.
#sequence.$arg1.sql
this line also fails as it will try to opens 2 files, one being called sequence.myvalue and another one called "%s", which i suspect the assigned variable contains some sort of unreadable nextline character.
EDIT: fixed, we can use the same treatment from sed - run sqlplus directly from plink instead of passing value and running a .sh script in Linux:
sqlplus $arg2/$arg2#MYDB #/myfilepath/sequence.%arg1%.sql
I'm new to linux scripting. I want to copy file from remote server to current server(executing or client server),required cert & key files are already installed on my server(client server). below commands work when I execute it individually in sequence but, after Integrating into a .sh script it doesnt!
--My Script--
lftp -u username,xxx -p 2121 remoteServer.net;
set ssl:cert-file /abc/def/etc/User_T.p12;
set ssl:key-file abc/def/etc/User_T.p12.pwd;
lftp -e 'set net:timeout 10; get /app/home/atm/feed.txt -o /com/data/';
man lftp:
-f script_file
Execute commands in the file and exit. This option must be used
alone without other arguments (except --norc).
-c commands
Execute the given commands and exit. Commands can be separated
with a semicolon, `&&' or `||'. Remember to quote the commands
argument properly in the shell. This option must be used alone
without other arguments (except --norc).
Use "here document" feature of the shell:
lftp <<EOF
set...
open...
get...
EOF
Thanks lav for your suggestion, I found that my script was not executing second line so added continuation like
<< SCRIPT
& ended script with SCRIPT
removed all semi colon... Its working
I want to execute a shell script in remote machine and i achieved this using the below command,
ssh user#remote_machine "bash -s" < /usr/test.sh
The shell script executed properly in the remote machine. Now i have made some changes in script to get some values from the config file. The script contains the below lines,
#!bin/bash
source /usr/property.config
echo "testName"
property.config :
testName=xxx
testPwd=yyy
Now if i run the shell script in remote machine, i am getting no such file error since /usr/property.config will not be available in remote machine.
How to pass the config file along with the shell script to be executed in remote machine ?
Only way you can reference to your config file that you created and still run your script is you need to put the config file at the required path there are two ways to do it.
If config is almost always fixed and you need not to change it, make the config locally on the host machine where you need to run the script then put the absolute path to the config file in your script and make sure the user running the script has permission to access it.
If need to ship your config file every time you want to run that script, then may just simply scp the file before you send and call the script.
scp property.config user#remote_machine:/usr/property.config
ssh user#remote_machine "bash -s" < /usr/test.sh
Edit
as per request if you want to forcefully do it in a single line this is how it can be done:
property.config
testName=xxx
testPwd=yyy
test.sh
#!bin/bash
#do not use this line source /usr/property.config
echo "$testName"
Now you can run your command as John has suggested:
ssh user#remote_machine "bash -s" < <(cat /usr/property.config /usr/test.sh)
Try this:
ssh user#remote_machine "bash -s" < <(cat /usr/property.config /usr/test.sh)
Then your script should not source the config internally.
Second option, if all you need to pass are environment variables:
There are a few techniques described here: https://superuser.com/questions/48783/how-can-i-pass-an-environment-variable-through-an-ssh-command
My favorite one is perhaps the simplest:
ssh user#remote_machine VAR1=val1 VAR2=val2 bash -s < /usr/test.sh
This of course means you'll need to build up the environment variable assignments from your local config file, but hopefully that's straightforward.
I am trying to run a script remotely using ssh and the need use some parameters from remote server. Kept all parameters in remote server location temp/test/test.prm file. Getting an error saying " invoke.sh: line 20: . /temp/test/test.prm: No such file or directory "
See below for sample script. Have very basic knowledge in scripting so plz direct me
#!/bin/sh
Param1=$1
Param2=$2
ssh usr#Server1
. ${Param1}/Client/scripts/Sample1.prm
cd $prmHome/$prmSetPath
ls | sed '/\.log$/d' > $prmHome/$prmScript/Filelist.txt
cd $prmHome/$prmScript
while read LINE
do
ExportFilName=$LINE
./conversion.sh $prmHome/tmp_export/convert_$Param2.csv $prmHome/$prmSetPath/'$ExportFilName'
done < Filelist.txt
rm -rf $prmHome/$prmScript/Filelist.txt
exit 0
Content of Sample1.prm
prmHome=/iis/home
prmSetPath=/export/set
PrmScript=/Client/scripts
I have tried the same trough command line after connecting to remote server using ssh and it is working, but when I am trying to do the same through a script (invoke.sh) its throwing no such file or directory error
UPDATE
This is unclear and will not work !
ssh usr#Server1
. ${Param1}/Client/scripts/Sample1.prm
As mentioned you should use
ssh usr#Server1 ". ${Param1}/Client/scripts/Sample1.prm"
format first.
And secondly what you expect following command to do ?
. ${Param1}/Client/scripts/Sample1.prm
Notice that there is a space in between . and the path, which is a synonym for source. So also check if the Sample1.prm have valid commands.
Looks like you are not running any ssh shell command on remote host but only on your local host.
How exactly you are running the ssh shell command ?
The code snippet in your example is poorly formatted.
The general structure should look like this e.g.
ssh user1#server1 date
or
ssh user1#server1 'df -H'
Please revise you invocation script, or make the formatting in the question appropriate.
Update:
If you want to execute your code on remote server via ssh, you can do following:
Create separate file my_script.sh for your code you want to run remotely, and paste following code:
#!/bin/bash
function my_function() {
prmHome=$1
prmSetPath=$2
PrmScript=$3
cd $prmHome/$prmSetPath
ls | sed '/\.log$/d' > $prmHome/$prmScript/Filelist.txt
cd $prmHome/$prmScript
while read LINE
do
ExportFilName=$LINE
./conversion.sh $prmHome/tmp_export/convert_$Param2.csv $prmHome/$prmSetPath/'$ExportFilName'
done < Filelist.txt
rm -rf $prmHome/$prmScript/Filelist.txt
exit 0
}
Then you can call you function remotely, by sourcing your file on remote server:
ssh usr#Server1 '. my_script.sh; my_function "/iis/home" "/export/set" "/Client/scripts"'
That's it :)
This code will not work:
ssh usr#Server1
. ${Param1}/Client/scripts/Sample1.prm
Change it like that:
ssh usr#Server1 ". ${Param1}/Client/scripts/Sample1.prm"
I'm running a batch file (export.bat) in Windows 7 using plink to execute a script in a remote Linux server machine, but I get this error:
./test.sh: line 3: back.sh: command not found
Batch file:
#echo off
cls
plink 1.1.10.11 -l user -pw pass "bash ./test.sh"
Script in the remote server:
#!/bin/sh
cd /path/path/path
script --table filename--filebase /path/path/path/path
exit
I'm assuming script in your remote script is actually back.sh, and that it exists in /path/path/path.
To execute a script back.sh in the directory you cd to (i.e. the current directory), use ./back.sh instead of just back.sh.
PS: You should generally try to avoid sanitizing input and output of things you post on StackOverflow. It often ends up confusing. For example, you say you get the error line 3: back.sh: command not found, but your remote script does not contain the command back.sh on line 3 or anywhere.
Instead, invest 15 minutes in making a runnable test case with no sensitive data, that you can actually execute and copy files and errors from verbatim. The bash tag wiki has tips for this.