Operating System - HP-UX
1752772 Members
5203 Online
108789 Solutions
New Discussion юеВ

Appending two file parllaly

 
Chandrahasa s
Valued Contributor

Appending two file parllaly

HI Gurus,

I have defined HISTFILE=/home/.sh_history
here all commands which i type will be appended to /home/.sh_history

I have created file /var/goodfile.Here my requirement is /var/goodfile also should also get appended with commands which i have typed parallely with /home/.sh_history

Chandra
8 REPLIES 8
Dennis Handly
Acclaimed Contributor

Re: Appending two file parllaly

About the best you can do is use the shell's history command to copy from ~/.sh_history to your file. You would have to do this every so often:
history -100 >> /var/goodfile
Chandrahasa s
Valued Contributor

Re: Appending two file parllaly

Thanks for reply,

Dennis if i do so there is possibility where same content appending multiple times to second file.

Chandra
Dennis Handly
Acclaimed Contributor

Re: Appending two file parllaly

>there is possibility where same content appending multiple times to second file.

Yes. If you don't want overlapping commands you will have to work harder:
history -100 >> /var/goodfile
last_history=$(history -0 | awk '{print $1}')

your commands ...

history $last_history >> /var/goodfile
last_history=$(history -0 | awk '{print $1}')

Then repeat.
Dennis Handly
Acclaimed Contributor

Re: Appending two file parllaly

>there is possibility where same content appending multiple times

Or you simply don't care and then you fix the output later:
sort -u /var/goodfile
rariasn
Honored Contributor

Re: Appending two file parllaly

Hi Chandra:

# tail -f /home/.sh_history >> /var/goodfile

rgs
Dennis Handly
Acclaimed Contributor

Re: Appending two file parllaly

>rariasn: # tail -f /home/.sh_history

Be aware that your shell history has binary data in it. Where the history command knows the format.
Viktor Balogh
Honored Contributor

Re: Appending two file parllaly

> Be aware that your shell history has binary data in it. Where the history command knows the format.

That's right. What if you would copy it real-time with a background dd? This dd won't terminate until it reaches an EOF. Maybe you could try it, I don't know if it works...
****
Unix operates with beer.
Dennis Handly
Acclaimed Contributor

Re: Appending two file parllaly

>Viktor: What if you would copy it real-time with a background dd? This dd won't terminate until it reaches an EOF.

Why would you use dd(1) when tail "works"?
(tail doesn't care about binary and doesn't stop at the EOF.)