Running Unix scrips from SSIS - unix

I am trying to run a Unix script which populates our Aged Debt table for our finance department from SSIS but cannot get my head around it. The script has to be run under user "username" and the script to run is :
P1='0*99999999' P2='2015_03_25*%%YY*Y' P3='Y*0.0' P4='Y*0.0' P5='Y*0.0' P6='Y*0.0' P7='Y*0.0' P8='Y*0.0' /cer_cerprod1/exe/par50219r
I believe that I need to have ssh configured on both sides to do this and I believe that I may do this from the "Execute Process Task" but I don't think that I am populating the parameters correctly.
Can anyone help.

I currently do this using putty/plink. Like sorrell says above, You use an execute process task to call a batch file. That batch file calls plink. I pass plink the shell script on the unix server that I want it to execute.
example of batch file:
echo y | "d:\program files\putty\plink.exe" [username#yourserver.com] -pw [password] -v sh /myremotescriptname.sh
the echo y at the beginning is to tell plink to accept the security credentials of the server.

Related

Unable to login to unix server using Plink in batch ifle

we are facing one issue with Plink while running the batch files, we are running batch files using autosys, the batch files are available in my windows client server and one of the batch file will call the plink to connect the unix server but we are facing the issue to connect the unix server, when I run the batch script using command prompt then the plink can be connected the unix server but it is not happening with autosys to run the batch scripts. below is the Plink command...
call %aScrDir%plink -l %hypSrvUser% -pw %hypSrvPwd% %essSvr% "sh /xxxxxxxxxxx"
when we see the error file which is generated by autosys there are some errors
"The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 f9:5e:2a:4a:11:ed:40:91:80:3a:13:04:08:05:e7:ac
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n) Connection abandoned."
could you please give the suggestion to avoid this situations and where do we add the host key in the server.
appreciate your action on this.
Option 1 : If allowed, first start a manual connection to the server and confirm the SSH key
Option 2 : If you are running the last version, there is a -hostkey switch to indicate in command line the expected host key
Option 3 : Use something like
echo N | %aScrDir%plink -l %hypSrvUser% -pw %hypSrvPwd% %essSvr% "sh /xxxxxxxxxxx"
That is, pipe the n character to the plink command to answer no to the query to save the host key.
Try this it would be working fine.
cd to the plink.exe file directory
echo Y | .\plink.exe -pw xxyyxxyy root#host_ip 'ls -lah'

PuTTY plink sending control+C

I am using Putty plink command line utility to run a few scripts on my UNIX server. I use the -m option as:
plink -ssh -pw xxx myserver –m file.txt
The file file.txt contains a list of commands that are to be executed and is generated dynamically using some application program. Some of the commands in file.txt can run for hours, which will make the user wait for a long time. Moreover, I am interested in execution of the first line of each of the scripts.
So I want to make sure that a control+c command is sent just after the script is run so that complete script is not run. So instead of using the following in my file.txt:
script1
script2
script3
I want to use:
script1
control+C command
script2
control+C command
script3
control+C command
Can anyone help me in writing this control+c in my file.txt?
Thanks a lot

nohup - dont want nohup.out but want log going to a different file on the remote server

I'm running the following command (where variables have valid values for ssh command and $file - is a .sql file).
nohup ssh -qn ${ssh_user}#${dbs} "sqlplus $dbuser/${dbpswd}#${dbname} <<ENDSQL | tee "${sql_run_output_file}".ssh.log
set echo off
set echo on
set timing on
set time on
set serveroutput on size 1000000
#${file}
ENDSQL
"
When I was using the above command without "nohup" before ssh command, after 1 hour or so, my connection from source server (where im running ssh) was getting an error/message "Connection reset...." and hanging my BASH shell script (which contains this ssh command in it). When, I use nohup, i dont see the connection issue.
Here's what I'm trying to get and need your help.
Change the command shown above so that the command will NOT create a nohup.out
(Did I read that I can use > instead of | tee ... and use 2>&1)
I DO NOT want to run the command giving a "&" (background)
I DO want a LOG file for the sqlplus session that's running on the target DB server via ssh command/connection (initiated from source server).
Thanks.
You can still lose the connection when running ssh under nohup, so it's not really a good solution. If possible, I would recommend that you copy the sql file via scp to the target server, then ssh in to the server, open a screen and run the command from there (Or run it under nohup). Is that an option?

How to redirect local ouput to stdin over ssh to remotely execute a local script?

i am trying to remotely execute a perl script that takes data from stdin, over ssh.
The tricky part is that i don't want to upload the script itself to the remote server.
The data that the remote script will read from stdin is produced by another perl script run locally.
Let's assume the following:
my local script producing data is called cron_extract_section.pl
my local script that will be run remotely is called cron_update_section.pl
both scripts take one argument on the command line, a simple word
I manage to execute the script remotely, if the script is present on the remote machine:
./cron_extract_section.pl ${SECTION} 2> /dev/null | ssh user#remote ~/path/to/remote/script/cron_update_section.pl ${SECTION}
I know also that i can run a script on a remote server without having to upload it first, using the following syntax:
ssh user#remote "perl - ${SECTION}" < ./cron_update_section.pl
What i can't figure out is how to feed the local script cron_update_section.pl over ssh to perl, AND also pipe the result of the local script cron_extract_section.pl to perl.
I tried the following, the perl script executes fine, but there is nothing to read from stdin:
./cron_extract_section.pl ${SECTION} 2> /dev/null | ssh user#remote perl - ${SECTION} < ./cron_update_section.pl
Do you know if it's possible to do so without modifying the scripts ?
Use the DATA file handle. In example:
Local script to be run on the remote machine:
# script.pl
while(<DATA>) {
print "# $_";
}
__DATA__
Then, run it as:
(cat script.pl && /cron_extract_section.pl ${SECTION}) | ssh $host perl

SharpSsh - script runs twice in csh and ksh

i'm running a script from ASP.NET/C# using SharpSsh. I realize when the script runs and i do a ps -ef grep from unix, i see the same script running twice, one in csh -c, and the other with ksh. The script has shebang ksh, so i'm not sure why a copy of csh is also running. Also if i run the same script directly from unix, only one copy runs with ksh. There's no other shell running from within the script.
Most Unix/Linux now have a command or option that will show process trees, with indented list like, look for -t or -T options to ps OR ptree OR ???
USER PID PPID START TT TIME CMD
daemon 1 1 11-03-06 ? 0 init
myusr 221568 1 11-03-07 tty10 1.00s \_ -ksh
myusr 350976 221568 07:52:11 tty10 0 | \_ ps -efT
I bet you'll see that the csh is the user login shell that includes your script as an argument ( you may have to use different options to ps to see the full command-line of the csh process) AND as a sub process you'll see ksh executing your script, and further sub-processes under ksh for any external commands that the script is calling.
I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, or give it a + (or -) as a useful answer.

Resources