DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

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

cnewtonne

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 117
How to pass a search result to an alias action as $$2
« on: July 13, 2016, 08: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
  • **
  • Posts: 117
Re: How to pass a search result to an alias action as $$2
« Reply #1 on: July 15, 2016, 03:17 PM »
Anybody home?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: How to pass a search result to an alias action as $$2
« Reply #2 on: July 15, 2016, 03:38 PM »
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.

Original address: https://www.donationcoder.com/forum/index.php?topic=42818.0