0

I am trying to run the informatica workflows thru ruby. Using the Net-ssh gem. When i run my test it gets passed but my jobs are not triggered when i check the logs they are not creating.

Below is my code.

Given(/^Run ESP jobs$/) do
  require 'net/ssh'
  Net::SSH.start('host', 'user', :password => "my_password" ) do
    # I am trying to connect to remote server.
    ssh.exec('cd /etl/dev/scripts/bin')
    puts ssh.exec('pwd')
    # After changing the directory i tried to see my path but my path still 
    # shows in the home 
    # below command is in this path "/etl/dev/scripts/bin"
    ssh.exec('startworkflow01.ksh folder_name workflow_name')
  end
end

I expect to run the job. Please provide me your suggestions in completing this task. Thanks for your valuable time.

anothermh
  • 9,815
  • 3
  • 33
  • 52
Phantom
  • 31
  • 2
  • 7
  • @engineersmnky thanks for your response, I did tried using exec!. Given(/^Run ESP jobs$/) do require 'net/ssh' Net::SSH.start('host', 'user', :password => "my_password" ) do |ssh| ssh.exec!('cd /etl/dev/scripts/bin') puts ssh.exec!('pwd') ssh.exec!('startworkflow01.ksh folder_name workflow_name') end end The test is getting passed but if i check the logs they are not generating any logs. When i run thru linux manually it works. – Phantom Jul 29 '19 at 19:49

1 Answers1

0

Neither exec nor exec! will preserve state between calls, since those commands are not running on top of a shell like Bash or Zsh.

Therefore to run a script in a certain folder you either have to address the script with an absolute path:

ssh.exec!("/the/path/to/my_script")

Or string related commands together with ; in the same exec call, to preserve state:

ssh.exec!("cd /the/path/to; my_script; ...")

If you want to run everything on top of a real shell, then it gets more complicated. I recommend to look here for more details on that:

ruby net-ssh login shell

Casper
  • 33,403
  • 4
  • 84
  • 79
  • Thanks for the reply. I tried using the below code Given(/^Run informatica jobs$/) do require 'net/ssh' Net::SSH.start('host', 'user', :password => "password" ) do |ssh| ssh.exec!( '/etl/dev/scripts/bin/startworkflow01.ksh app_CCMLB_FPERX wf_4100_CCML_CAP_PKG_EXT') end end Still i dont see any logs for it. – Phantom Jul 29 '19 at 21:23
  • And does startworkflow01.ksh expect a particular working directory? Does it expect other shell variables to be present? Note that it is NOT a login shell, so no `.bashrc` files will be run to set up your environment. – Casper Jul 29 '19 at 21:27
  • I kind of able to change the dir. When i run the test, I am getting this bash: startworkflow01.ksh: command not found. startworkflow01.ksh is present in the path above mentioned. I am not sure what it means. – Phantom Jul 30 '19 at 15:42
  • You should run it with `./startworkflow01.ksh`. Note the dot and slash. Like I said your environment will not be set up. If it does not work you would be better off using something like `Net::SSH::Shell` instead: https://github.com/mitchellh/net-ssh-shell – Casper Jul 30 '19 at 15:56