[SOLVED] [bash] consolidate multiple ssh commands into 1
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
seems kinda' inefficient to call ssh twice... i tired embedding them using `backticks`, "'quotes'", (parenthesis) but nothing seems to work. is this possible or should i just live with it ?
f=`ssh hyper ls -1 /path/to/some/file | tail -n 1`
How does the effoct of the above line differ from:
Code:
f=/path/to/some/file
hi mina, becuz the last file in that directory will be date-stamped every friday (e.g.- log_2013-03-29.txt , last week the file would be log_2013-03-22.txt).
Well my first impression is why do you use both `` and $()? I personally prefer the second but it does not seem to make it easy to follow if you change in and out of the two.
As for calling the ssh once, I believe the parenthesis option should work:
It would appear that the several greps and cut seem a bit excessive. I know it is aix but I would have thought even its awk would do this a bit cleaner.
And place any of those statements in f=$(). Or if you could perhaps in fn=$() already. You should just note that everything sent to remote bash would be executed remotely as is.
Add: Sometimes you could also just use other shells. You just have to make your commands would work with them.
Last edited by konsolebox; 04-05-2013 at 12:14 AM.
hi mina, becuz the last file in that directory will be date-stamped every friday (e.g.- log_2013-03-29.txt , last week the file would be log_2013-03-22.txt).
Ah, so /path/to/some/file is really /path/to/some/directory.
Well my first impression is why do you use both `` and $()? I personally prefer the second but it does not seem to make it easy to follow if you change in and out of the two.
As for calling the ssh once, I believe the parenthesis option should work:
It would appear that the several greps and cut seem a bit excessive. I know it is aix but I would have thought even its awk would do this a bit cleaner.
i think with this i got path not found errors becuz it was looking for /path/to/some/file on the local machine (which doesnt exists).
i think konsolebox's idea of piping into ssh looks promising.
just had another clever idea; maybe running find with -mtime -7 (each friday) and -exec cut ... grep ... uniq. maybe i can even cat the contents of the scraped filename and redirect it to a file on the local machine rather than calling scp independently.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.