topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday March 29, 2024, 2:48 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: How to pass a search result to an alias action as $$2  (Read 3368 times)

cnewtonne

  • Honorary Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 117
    • View Profile
    • Donate to Member
How to pass a search result to an alias action as $$2
« on: July 13, 2016, 03:21 PM »
Hi all ....
I'm trying to automate logging in to remote hosts via ss and execute shell scripts saved in a local folder on the PC. The final commands looks like this

ssh user@host_name my_shell_script.sh

I have 2 variables. First is host_name and a second is my_shell_script.sh

I created 2 aliases ...
1) script_lib which does a 'dosearch' on the folder where scripts are saved
2) exec_ssh defined as 'ssh (.*) (.*) and the pass to the ssh binary 'c:\....\ssh.exe jsmith@$$1 $$2'

In the farr search box I type ....

script_lib get_host_name.sh +exec_ssh

This command passes the get_host_name.sh search hit as $$1 to action alias +exec_ssh. It needs to pass as $$2 since $$1 is the host name. The tool I'm using requires this ordering of arguments.

How can I do this in farr, please.

Thanks

cnewtonne

  • Honorary Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 117
    • View Profile
    • Donate to Member
Re: How to pass a search result to an alias action as $$2
« Reply #1 on: July 15, 2016, 10:17 AM »
Anybody home?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: How to pass a search result to an alias action as $$2
« Reply #2 on: July 15, 2016, 10:38 AM »
Sorry for the delay in replying..

It sounds like you are doing things right with the exec_ssh regex, and that should work passing both arguments.

The tricky part is how you are using the script_lib dosearch using the + thing.. That is getting a little advanced..

I wonder if you could solve it like this:
In the script_lib alias result, do a setuservar command to save the value of $$2 to a temporary variable like "uservar.temp.sshvar2", and then create a new exec_ssh replacement alias that only expects $$1 and then uses "%uservar.temp.sshvar2%" instead of $$2.