gmendonca / parallel-ssh

Automatically exported from code.google.com/p/parallel-ssh
Other
1 stars 0 forks source link

output filename format (patch available) #22

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I would like to able to define a format for the name of the output file. Eg. 
%host_%Y%M%D_%H%M.txt. That way it would be able to keep multiple logfiles 
collected during the day... :-) 

Original issue reported on code.google.com by mencoper...@gmail.com on 21 Jul 2010 at 6:33

GoogleCodeExporter commented 8 years ago
Sorry for the late response.  This sounds like a nice feature, but 
unfortunately, it probably won't be highest priority.  If you include a patch, 
it will definitely go more quickly.  Anyway, this does sound like a very handy 
feature.  Thanks for posting the request.

Original comment by amcna...@gmail.com on 9 Jan 2011 at 6:18

GoogleCodeExporter commented 8 years ago
All that would be needed is the ability to substitute %h (for example) in a 
format string.  Everything else can be accomplished with the shell's process 
substitution: I.e.

Imagine %h gets substituted by the hostname:

--stdout-filespec "./stdout/$(date +%Y%m%d)/%h.txt"

I attach a quick'n'dirty patch that achieves this

# directories have to exist with this patch
mkdir dir
./bin/pssh -o "dir/file_%h_$(date +%Y%m%d)_stdout" -e "dir/file_%h_$(date 
+%Y%m%d)_stderr" -h list hostname

ls dir
file_h1_20110902_stderr
file_h2_20110902_stdout
[..etc..]

Original comment by pablo.ba...@gmail.com on 2 Sep 2011 at 11:57

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for sharing the patch. I'll take a look at it soon.

Original comment by amcna...@gmail.com on 5 Sep 2011 at 2:25

GoogleCodeExporter commented 8 years ago
just a bit curious where this is at.....

Original comment by jcp...@gmail.com on 11 Jan 2013 at 6:06

GoogleCodeExporter commented 8 years ago
jcpunk, thanks for the reminder. I think it's a fantastic idea. A few issues 
that we should address before implementing this:

1) There needs to be an escape sequence. For example, the FORMAT spec detailed 
in the man page for date includes "%%" for allowing a literal "%" character.

2) There are probably some other types of information that would be useful to 
include, and it would be nice to explore some of the possibilities before 
implementing.

3) The way that stdout files are currently created, the first time a host "xyz" 
appears, the file is named "xyz", and if it's listed a second time in the hosts 
list, then a "xyz.1" file will be created, etc. The issue of hosts occurring 
multiple times should be addressed.

Anyway, I think this is a very desirable feature.

Original comment by amcna...@gmail.com on 14 Jan 2013 at 4:38

GoogleCodeExporter commented 8 years ago
I was thinking about how to transform the patch to meet these suggestions and 
ran into an odd outcome.

Don't want to radically alter the behaviour of -e or -o as that breaks 
backwards compatibility for this specialized feature.

So, what would a sensible command line argument look like?

Upon further reflection I'm thinking a simpler way to achieve the end result of 
the initial request might be a non-pssh solution.

Am I headed in the right direction?

pssh -o "$(date +%Y%m%d)_stdout" -e "$(date +%Y%m%d)_stderr" -h list 'uname -r' 

The end logs are in a uniquely-ish named dir and subsequent runs do not 
eliminate existing logs.

Logs for a given day are automatically stored in the directory and parse-able.  
Native OS tools could be used to rename them to any format desired.

For my use case this is a sufficient solution.

Original comment by jcp...@gmail.com on 14 Jan 2013 at 6:01

GoogleCodeExporter commented 8 years ago
It wasn't too hard to add a way of simply munging the output names if that 
proves valuable.

As an aside a workable regex for leaving %% alone while matching %h is

re.sub('[^%]%h', 'hostname', string)

Original comment by jcp...@gmail.com on 14 Jan 2013 at 6:02

Attachments:

GoogleCodeExporter commented 8 years ago
As you suggested, for just changing the names of the directories, something 
like `pssh -o "$(date +%Y%m%d)_stdout" -e "$(date +%Y%m%d)_stderr" -h list 
'uname -r'` works great. This is what I've personally done in the past, and 
maybe that's the best way to do it. Having a full format spec language might be 
useful if there are more types of information that would be useful to include, 
beyond just the hostname and date.

Original comment by amcna...@gmail.com on 14 Jan 2013 at 6:53